Home | History | Annotate | Line # | Download | only in drm
drm_edid.c revision 1.5.16.1
      1  1.5.16.1  pgoyette /*	$NetBSD: drm_edid.c,v 1.5.16.1 2018/09/06 06:56:09 pgoyette Exp $	*/
      2  1.5.16.1  pgoyette 
      3       1.1  riastrad /*
      4       1.1  riastrad  * Copyright (c) 2006 Luc Verhaegen (quirks list)
      5       1.1  riastrad  * Copyright (c) 2007-2008 Intel Corporation
      6       1.1  riastrad  *   Jesse Barnes <jesse.barnes (at) intel.com>
      7       1.1  riastrad  * Copyright 2010 Red Hat, Inc.
      8       1.1  riastrad  *
      9       1.1  riastrad  * DDC probing routines (drm_ddc_read & drm_do_probe_ddc_edid) originally from
     10       1.1  riastrad  * FB layer.
     11       1.1  riastrad  *   Copyright (C) 2006 Dennis Munsie <dmunsie (at) cecropia.com>
     12       1.1  riastrad  *
     13       1.1  riastrad  * Permission is hereby granted, free of charge, to any person obtaining a
     14       1.1  riastrad  * copy of this software and associated documentation files (the "Software"),
     15       1.1  riastrad  * to deal in the Software without restriction, including without limitation
     16       1.1  riastrad  * the rights to use, copy, modify, merge, publish, distribute, sub license,
     17       1.1  riastrad  * and/or sell copies of the Software, and to permit persons to whom the
     18       1.1  riastrad  * Software is furnished to do so, subject to the following conditions:
     19       1.1  riastrad  *
     20       1.1  riastrad  * The above copyright notice and this permission notice (including the
     21       1.1  riastrad  * next paragraph) shall be included in all copies or substantial portions
     22       1.1  riastrad  * of the Software.
     23       1.1  riastrad  *
     24       1.1  riastrad  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     25       1.1  riastrad  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     26       1.1  riastrad  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
     27       1.1  riastrad  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     28       1.1  riastrad  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     29       1.1  riastrad  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
     30       1.1  riastrad  * DEALINGS IN THE SOFTWARE.
     31       1.1  riastrad  */
     32  1.5.16.1  pgoyette #include <sys/cdefs.h>
     33  1.5.16.1  pgoyette __KERNEL_RCSID(0, "$NetBSD: drm_edid.c,v 1.5.16.1 2018/09/06 06:56:09 pgoyette Exp $");
     34  1.5.16.1  pgoyette 
     35       1.1  riastrad #include <linux/kernel.h>
     36       1.1  riastrad #include <linux/slab.h>
     37       1.3  riastrad #include <linux/hdmi.h>
     38       1.1  riastrad #include <linux/i2c.h>
     39       1.1  riastrad #include <linux/module.h>
     40       1.2  riastrad #include <linux/moduleparam.h>
     41       1.2  riastrad #include <linux/export.h>
     42       1.2  riastrad #include <linux/printk.h>
     43       1.2  riastrad #include <linux/device.h>
     44       1.2  riastrad #include <linux/string.h>
     45       1.4  riastrad #include <linux/errno.h>
     46       1.2  riastrad #include <asm/byteorder.h>
     47       1.1  riastrad #include <drm/drmP.h>
     48       1.1  riastrad #include <drm/drm_edid.h>
     49  1.5.16.1  pgoyette #include <drm/drm_displayid.h>
     50       1.1  riastrad 
     51       1.1  riastrad #define version_greater(edid, maj, min) \
     52       1.1  riastrad 	(((edid)->version > (maj)) || \
     53       1.1  riastrad 	 ((edid)->version == (maj) && (edid)->revision > (min)))
     54       1.1  riastrad 
     55       1.1  riastrad #define EDID_EST_TIMINGS 16
     56       1.1  riastrad #define EDID_STD_TIMINGS 8
     57       1.1  riastrad #define EDID_DETAILED_TIMINGS 4
     58       1.1  riastrad 
     59       1.1  riastrad /*
     60       1.1  riastrad  * EDID blocks out in the wild have a variety of bugs, try to collect
     61       1.1  riastrad  * them here (note that userspace may work around broken monitors first,
     62       1.1  riastrad  * but fixes should make their way here so that the kernel "just works"
     63       1.1  riastrad  * on as many displays as possible).
     64       1.1  riastrad  */
     65       1.1  riastrad 
     66       1.1  riastrad /* First detailed mode wrong, use largest 60Hz mode */
     67       1.1  riastrad #define EDID_QUIRK_PREFER_LARGE_60		(1 << 0)
     68       1.1  riastrad /* Reported 135MHz pixel clock is too high, needs adjustment */
     69       1.1  riastrad #define EDID_QUIRK_135_CLOCK_TOO_HIGH		(1 << 1)
     70       1.1  riastrad /* Prefer the largest mode at 75 Hz */
     71       1.1  riastrad #define EDID_QUIRK_PREFER_LARGE_75		(1 << 2)
     72       1.1  riastrad /* Detail timing is in cm not mm */
     73       1.1  riastrad #define EDID_QUIRK_DETAILED_IN_CM		(1 << 3)
     74       1.1  riastrad /* Detailed timing descriptors have bogus size values, so just take the
     75       1.1  riastrad  * maximum size and use that.
     76       1.1  riastrad  */
     77       1.1  riastrad #define EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE	(1 << 4)
     78       1.1  riastrad /* Monitor forgot to set the first detailed is preferred bit. */
     79       1.1  riastrad #define EDID_QUIRK_FIRST_DETAILED_PREFERRED	(1 << 5)
     80       1.1  riastrad /* use +hsync +vsync for detailed mode */
     81       1.1  riastrad #define EDID_QUIRK_DETAILED_SYNC_PP		(1 << 6)
     82       1.1  riastrad /* Force reduced-blanking timings for detailed modes */
     83       1.1  riastrad #define EDID_QUIRK_FORCE_REDUCED_BLANKING	(1 << 7)
     84       1.3  riastrad /* Force 8bpc */
     85       1.3  riastrad #define EDID_QUIRK_FORCE_8BPC			(1 << 8)
     86  1.5.16.1  pgoyette /* Force 12bpc */
     87  1.5.16.1  pgoyette #define EDID_QUIRK_FORCE_12BPC			(1 << 9)
     88  1.5.16.1  pgoyette /* Force 6bpc */
     89  1.5.16.1  pgoyette #define EDID_QUIRK_FORCE_6BPC			(1 << 10)
     90  1.5.16.1  pgoyette /* Force 10bpc */
     91  1.5.16.1  pgoyette #define EDID_QUIRK_FORCE_10BPC			(1 << 11)
     92       1.1  riastrad 
     93       1.1  riastrad struct detailed_mode_closure {
     94       1.1  riastrad 	struct drm_connector *connector;
     95       1.1  riastrad 	struct edid *edid;
     96       1.1  riastrad 	bool preferred;
     97       1.1  riastrad 	u32 quirks;
     98       1.1  riastrad 	int modes;
     99       1.1  riastrad };
    100       1.1  riastrad 
    101       1.1  riastrad #define LEVEL_DMT	0
    102       1.1  riastrad #define LEVEL_GTF	1
    103       1.1  riastrad #define LEVEL_GTF2	2
    104       1.1  riastrad #define LEVEL_CVT	3
    105       1.1  riastrad 
    106       1.1  riastrad static struct edid_quirk {
    107       1.1  riastrad 	char vendor[4];
    108       1.1  riastrad 	int product_id;
    109       1.1  riastrad 	u32 quirks;
    110       1.1  riastrad } edid_quirk_list[] = {
    111       1.1  riastrad 	/* Acer AL1706 */
    112       1.1  riastrad 	{ "ACR", 44358, EDID_QUIRK_PREFER_LARGE_60 },
    113       1.1  riastrad 	/* Acer F51 */
    114       1.1  riastrad 	{ "API", 0x7602, EDID_QUIRK_PREFER_LARGE_60 },
    115       1.1  riastrad 	/* Unknown Acer */
    116       1.1  riastrad 	{ "ACR", 2423, EDID_QUIRK_FIRST_DETAILED_PREFERRED },
    117       1.1  riastrad 
    118  1.5.16.1  pgoyette 	/* AEO model 0 reports 8 bpc, but is a 6 bpc panel */
    119  1.5.16.1  pgoyette 	{ "AEO", 0, EDID_QUIRK_FORCE_6BPC },
    120  1.5.16.1  pgoyette 
    121  1.5.16.1  pgoyette 	/* CPT panel of Asus UX303LA reports 8 bpc, but is a 6 bpc panel */
    122  1.5.16.1  pgoyette 	{ "CPT", 0x17df, EDID_QUIRK_FORCE_6BPC },
    123  1.5.16.1  pgoyette 
    124       1.1  riastrad 	/* Belinea 10 15 55 */
    125       1.1  riastrad 	{ "MAX", 1516, EDID_QUIRK_PREFER_LARGE_60 },
    126       1.1  riastrad 	{ "MAX", 0x77e, EDID_QUIRK_PREFER_LARGE_60 },
    127       1.1  riastrad 
    128       1.1  riastrad 	/* Envision Peripherals, Inc. EN-7100e */
    129       1.1  riastrad 	{ "EPI", 59264, EDID_QUIRK_135_CLOCK_TOO_HIGH },
    130       1.1  riastrad 	/* Envision EN2028 */
    131       1.1  riastrad 	{ "EPI", 8232, EDID_QUIRK_PREFER_LARGE_60 },
    132       1.1  riastrad 
    133       1.1  riastrad 	/* Funai Electronics PM36B */
    134       1.1  riastrad 	{ "FCM", 13600, EDID_QUIRK_PREFER_LARGE_75 |
    135       1.1  riastrad 	  EDID_QUIRK_DETAILED_IN_CM },
    136       1.1  riastrad 
    137  1.5.16.1  pgoyette 	/* LGD panel of HP zBook 17 G2, eDP 10 bpc, but reports unknown bpc */
    138  1.5.16.1  pgoyette 	{ "LGD", 764, EDID_QUIRK_FORCE_10BPC },
    139  1.5.16.1  pgoyette 
    140       1.1  riastrad 	/* LG Philips LCD LP154W01-A5 */
    141       1.1  riastrad 	{ "LPL", 0, EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE },
    142       1.1  riastrad 	{ "LPL", 0x2a00, EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE },
    143       1.1  riastrad 
    144       1.1  riastrad 	/* Philips 107p5 CRT */
    145       1.1  riastrad 	{ "PHL", 57364, EDID_QUIRK_FIRST_DETAILED_PREFERRED },
    146       1.1  riastrad 
    147       1.1  riastrad 	/* Proview AY765C */
    148       1.1  riastrad 	{ "PTS", 765, EDID_QUIRK_FIRST_DETAILED_PREFERRED },
    149       1.1  riastrad 
    150       1.1  riastrad 	/* Samsung SyncMaster 205BW.  Note: irony */
    151       1.1  riastrad 	{ "SAM", 541, EDID_QUIRK_DETAILED_SYNC_PP },
    152       1.1  riastrad 	/* Samsung SyncMaster 22[5-6]BW */
    153       1.1  riastrad 	{ "SAM", 596, EDID_QUIRK_PREFER_LARGE_60 },
    154       1.1  riastrad 	{ "SAM", 638, EDID_QUIRK_PREFER_LARGE_60 },
    155       1.1  riastrad 
    156  1.5.16.1  pgoyette 	/* Sony PVM-2541A does up to 12 bpc, but only reports max 8 bpc */
    157  1.5.16.1  pgoyette 	{ "SNY", 0x2541, EDID_QUIRK_FORCE_12BPC },
    158  1.5.16.1  pgoyette 
    159       1.1  riastrad 	/* ViewSonic VA2026w */
    160       1.1  riastrad 	{ "VSC", 5020, EDID_QUIRK_FORCE_REDUCED_BLANKING },
    161       1.3  riastrad 
    162       1.3  riastrad 	/* Medion MD 30217 PG */
    163       1.3  riastrad 	{ "MED", 0x7b8, EDID_QUIRK_PREFER_LARGE_75 },
    164       1.3  riastrad 
    165       1.3  riastrad 	/* Panel in Samsung NP700G7A-S01PL notebook reports 6bpc */
    166       1.3  riastrad 	{ "SEC", 0xd033, EDID_QUIRK_FORCE_8BPC },
    167  1.5.16.1  pgoyette 
    168  1.5.16.1  pgoyette 	/* Rotel RSX-1058 forwards sink's EDID but only does HDMI 1.1*/
    169  1.5.16.1  pgoyette 	{ "ETR", 13896, EDID_QUIRK_FORCE_8BPC },
    170       1.3  riastrad };
    171       1.3  riastrad 
    172       1.3  riastrad /*
    173       1.3  riastrad  * Autogenerated from the DMT spec.
    174       1.3  riastrad  * This table is copied from xfree86/modes/xf86EdidModes.c.
    175       1.3  riastrad  */
    176       1.3  riastrad static const struct drm_display_mode drm_dmt_modes[] = {
    177  1.5.16.1  pgoyette 	/* 0x01 - 640x350@85Hz */
    178       1.3  riastrad 	{ DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
    179       1.3  riastrad 		   736, 832, 0, 350, 382, 385, 445, 0,
    180       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
    181  1.5.16.1  pgoyette 	/* 0x02 - 640x400@85Hz */
    182       1.3  riastrad 	{ DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
    183       1.3  riastrad 		   736, 832, 0, 400, 401, 404, 445, 0,
    184       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
    185  1.5.16.1  pgoyette 	/* 0x03 - 720x400@85Hz */
    186       1.3  riastrad 	{ DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 756,
    187       1.3  riastrad 		   828, 936, 0, 400, 401, 404, 446, 0,
    188       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
    189  1.5.16.1  pgoyette 	/* 0x04 - 640x480@60Hz */
    190       1.3  riastrad 	{ DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
    191  1.5.16.1  pgoyette 		   752, 800, 0, 480, 490, 492, 525, 0,
    192       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
    193  1.5.16.1  pgoyette 	/* 0x05 - 640x480@72Hz */
    194       1.3  riastrad 	{ DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
    195       1.3  riastrad 		   704, 832, 0, 480, 489, 492, 520, 0,
    196       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
    197  1.5.16.1  pgoyette 	/* 0x06 - 640x480@75Hz */
    198       1.3  riastrad 	{ DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
    199       1.3  riastrad 		   720, 840, 0, 480, 481, 484, 500, 0,
    200       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
    201  1.5.16.1  pgoyette 	/* 0x07 - 640x480@85Hz */
    202       1.3  riastrad 	{ DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 36000, 640, 696,
    203       1.3  riastrad 		   752, 832, 0, 480, 481, 484, 509, 0,
    204       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
    205  1.5.16.1  pgoyette 	/* 0x08 - 800x600@56Hz */
    206       1.3  riastrad 	{ DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
    207       1.3  riastrad 		   896, 1024, 0, 600, 601, 603, 625, 0,
    208       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
    209  1.5.16.1  pgoyette 	/* 0x09 - 800x600@60Hz */
    210       1.3  riastrad 	{ DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
    211       1.3  riastrad 		   968, 1056, 0, 600, 601, 605, 628, 0,
    212       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
    213  1.5.16.1  pgoyette 	/* 0x0a - 800x600@72Hz */
    214       1.3  riastrad 	{ DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
    215       1.3  riastrad 		   976, 1040, 0, 600, 637, 643, 666, 0,
    216       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
    217  1.5.16.1  pgoyette 	/* 0x0b - 800x600@75Hz */
    218       1.3  riastrad 	{ DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
    219       1.3  riastrad 		   896, 1056, 0, 600, 601, 604, 625, 0,
    220       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
    221  1.5.16.1  pgoyette 	/* 0x0c - 800x600@85Hz */
    222       1.3  riastrad 	{ DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 56250, 800, 832,
    223       1.3  riastrad 		   896, 1048, 0, 600, 601, 604, 631, 0,
    224       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
    225  1.5.16.1  pgoyette 	/* 0x0d - 800x600@120Hz RB */
    226       1.3  riastrad 	{ DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 73250, 800, 848,
    227       1.3  riastrad 		   880, 960, 0, 600, 603, 607, 636, 0,
    228       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
    229  1.5.16.1  pgoyette 	/* 0x0e - 848x480@60Hz */
    230       1.3  riastrad 	{ DRM_MODE("848x480", DRM_MODE_TYPE_DRIVER, 33750, 848, 864,
    231       1.3  riastrad 		   976, 1088, 0, 480, 486, 494, 517, 0,
    232       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
    233  1.5.16.1  pgoyette 	/* 0x0f - 1024x768@43Hz, interlace */
    234       1.3  riastrad 	{ DRM_MODE("1024x768i", DRM_MODE_TYPE_DRIVER, 44900, 1024, 1032,
    235       1.3  riastrad 		   1208, 1264, 0, 768, 768, 772, 817, 0,
    236       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
    237  1.5.16.1  pgoyette 		   DRM_MODE_FLAG_INTERLACE) },
    238  1.5.16.1  pgoyette 	/* 0x10 - 1024x768@60Hz */
    239       1.3  riastrad 	{ DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
    240       1.3  riastrad 		   1184, 1344, 0, 768, 771, 777, 806, 0,
    241       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
    242  1.5.16.1  pgoyette 	/* 0x11 - 1024x768@70Hz */
    243       1.3  riastrad 	{ DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
    244       1.3  riastrad 		   1184, 1328, 0, 768, 771, 777, 806, 0,
    245       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
    246  1.5.16.1  pgoyette 	/* 0x12 - 1024x768@75Hz */
    247       1.3  riastrad 	{ DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78750, 1024, 1040,
    248       1.3  riastrad 		   1136, 1312, 0, 768, 769, 772, 800, 0,
    249       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
    250  1.5.16.1  pgoyette 	/* 0x13 - 1024x768@85Hz */
    251       1.3  riastrad 	{ DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 94500, 1024, 1072,
    252       1.3  riastrad 		   1168, 1376, 0, 768, 769, 772, 808, 0,
    253       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
    254  1.5.16.1  pgoyette 	/* 0x14 - 1024x768@120Hz RB */
    255       1.3  riastrad 	{ DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 115500, 1024, 1072,
    256       1.3  riastrad 		   1104, 1184, 0, 768, 771, 775, 813, 0,
    257       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
    258  1.5.16.1  pgoyette 	/* 0x15 - 1152x864@75Hz */
    259       1.3  riastrad 	{ DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
    260       1.3  riastrad 		   1344, 1600, 0, 864, 865, 868, 900, 0,
    261       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
    262  1.5.16.1  pgoyette 	/* 0x55 - 1280x720@60Hz */
    263  1.5.16.1  pgoyette 	{ DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
    264  1.5.16.1  pgoyette 		   1430, 1650, 0, 720, 725, 730, 750, 0,
    265  1.5.16.1  pgoyette 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
    266  1.5.16.1  pgoyette 	/* 0x16 - 1280x768@60Hz RB */
    267       1.3  riastrad 	{ DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 68250, 1280, 1328,
    268       1.3  riastrad 		   1360, 1440, 0, 768, 771, 778, 790, 0,
    269       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
    270  1.5.16.1  pgoyette 	/* 0x17 - 1280x768@60Hz */
    271       1.3  riastrad 	{ DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 79500, 1280, 1344,
    272       1.3  riastrad 		   1472, 1664, 0, 768, 771, 778, 798, 0,
    273       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
    274  1.5.16.1  pgoyette 	/* 0x18 - 1280x768@75Hz */
    275       1.3  riastrad 	{ DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 102250, 1280, 1360,
    276       1.3  riastrad 		   1488, 1696, 0, 768, 771, 778, 805, 0,
    277  1.5.16.1  pgoyette 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
    278  1.5.16.1  pgoyette 	/* 0x19 - 1280x768@85Hz */
    279       1.3  riastrad 	{ DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 117500, 1280, 1360,
    280       1.3  riastrad 		   1496, 1712, 0, 768, 771, 778, 809, 0,
    281       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
    282  1.5.16.1  pgoyette 	/* 0x1a - 1280x768@120Hz RB */
    283       1.3  riastrad 	{ DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 140250, 1280, 1328,
    284       1.3  riastrad 		   1360, 1440, 0, 768, 771, 778, 813, 0,
    285       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
    286  1.5.16.1  pgoyette 	/* 0x1b - 1280x800@60Hz RB */
    287       1.3  riastrad 	{ DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 71000, 1280, 1328,
    288       1.3  riastrad 		   1360, 1440, 0, 800, 803, 809, 823, 0,
    289       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
    290  1.5.16.1  pgoyette 	/* 0x1c - 1280x800@60Hz */
    291       1.3  riastrad 	{ DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 83500, 1280, 1352,
    292       1.3  riastrad 		   1480, 1680, 0, 800, 803, 809, 831, 0,
    293  1.5.16.1  pgoyette 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
    294  1.5.16.1  pgoyette 	/* 0x1d - 1280x800@75Hz */
    295       1.3  riastrad 	{ DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 106500, 1280, 1360,
    296       1.3  riastrad 		   1488, 1696, 0, 800, 803, 809, 838, 0,
    297       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
    298  1.5.16.1  pgoyette 	/* 0x1e - 1280x800@85Hz */
    299       1.3  riastrad 	{ DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 122500, 1280, 1360,
    300       1.3  riastrad 		   1496, 1712, 0, 800, 803, 809, 843, 0,
    301       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
    302  1.5.16.1  pgoyette 	/* 0x1f - 1280x800@120Hz RB */
    303       1.3  riastrad 	{ DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 146250, 1280, 1328,
    304       1.3  riastrad 		   1360, 1440, 0, 800, 803, 809, 847, 0,
    305       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
    306  1.5.16.1  pgoyette 	/* 0x20 - 1280x960@60Hz */
    307       1.3  riastrad 	{ DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1376,
    308       1.3  riastrad 		   1488, 1800, 0, 960, 961, 964, 1000, 0,
    309       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
    310  1.5.16.1  pgoyette 	/* 0x21 - 1280x960@85Hz */
    311       1.3  riastrad 	{ DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1344,
    312       1.3  riastrad 		   1504, 1728, 0, 960, 961, 964, 1011, 0,
    313       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
    314  1.5.16.1  pgoyette 	/* 0x22 - 1280x960@120Hz RB */
    315       1.3  riastrad 	{ DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 175500, 1280, 1328,
    316       1.3  riastrad 		   1360, 1440, 0, 960, 963, 967, 1017, 0,
    317       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
    318  1.5.16.1  pgoyette 	/* 0x23 - 1280x1024@60Hz */
    319       1.3  riastrad 	{ DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1328,
    320       1.3  riastrad 		   1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
    321       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
    322  1.5.16.1  pgoyette 	/* 0x24 - 1280x1024@75Hz */
    323       1.3  riastrad 	{ DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
    324       1.3  riastrad 		   1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
    325       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
    326  1.5.16.1  pgoyette 	/* 0x25 - 1280x1024@85Hz */
    327       1.3  riastrad 	{ DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 157500, 1280, 1344,
    328       1.3  riastrad 		   1504, 1728, 0, 1024, 1025, 1028, 1072, 0,
    329       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
    330  1.5.16.1  pgoyette 	/* 0x26 - 1280x1024@120Hz RB */
    331       1.3  riastrad 	{ DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 187250, 1280, 1328,
    332       1.3  riastrad 		   1360, 1440, 0, 1024, 1027, 1034, 1084, 0,
    333       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
    334  1.5.16.1  pgoyette 	/* 0x27 - 1360x768@60Hz */
    335       1.3  riastrad 	{ DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 85500, 1360, 1424,
    336       1.3  riastrad 		   1536, 1792, 0, 768, 771, 777, 795, 0,
    337       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
    338  1.5.16.1  pgoyette 	/* 0x28 - 1360x768@120Hz RB */
    339       1.3  riastrad 	{ DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 148250, 1360, 1408,
    340       1.3  riastrad 		   1440, 1520, 0, 768, 771, 776, 813, 0,
    341       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
    342  1.5.16.1  pgoyette 	/* 0x51 - 1366x768@60Hz */
    343  1.5.16.1  pgoyette 	{ DRM_MODE("1366x768", DRM_MODE_TYPE_DRIVER, 85500, 1366, 1436,
    344  1.5.16.1  pgoyette 		   1579, 1792, 0, 768, 771, 774, 798, 0,
    345  1.5.16.1  pgoyette 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
    346  1.5.16.1  pgoyette 	/* 0x56 - 1366x768@60Hz */
    347  1.5.16.1  pgoyette 	{ DRM_MODE("1366x768", DRM_MODE_TYPE_DRIVER, 72000, 1366, 1380,
    348  1.5.16.1  pgoyette 		   1436, 1500, 0, 768, 769, 772, 800, 0,
    349  1.5.16.1  pgoyette 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
    350  1.5.16.1  pgoyette 	/* 0x29 - 1400x1050@60Hz RB */
    351       1.3  riastrad 	{ DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 101000, 1400, 1448,
    352       1.3  riastrad 		   1480, 1560, 0, 1050, 1053, 1057, 1080, 0,
    353       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
    354  1.5.16.1  pgoyette 	/* 0x2a - 1400x1050@60Hz */
    355       1.3  riastrad 	{ DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 121750, 1400, 1488,
    356       1.3  riastrad 		   1632, 1864, 0, 1050, 1053, 1057, 1089, 0,
    357       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
    358  1.5.16.1  pgoyette 	/* 0x2b - 1400x1050@75Hz */
    359       1.3  riastrad 	{ DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 156000, 1400, 1504,
    360       1.3  riastrad 		   1648, 1896, 0, 1050, 1053, 1057, 1099, 0,
    361       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
    362  1.5.16.1  pgoyette 	/* 0x2c - 1400x1050@85Hz */
    363       1.3  riastrad 	{ DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 179500, 1400, 1504,
    364       1.3  riastrad 		   1656, 1912, 0, 1050, 1053, 1057, 1105, 0,
    365       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
    366  1.5.16.1  pgoyette 	/* 0x2d - 1400x1050@120Hz RB */
    367       1.3  riastrad 	{ DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 208000, 1400, 1448,
    368       1.3  riastrad 		   1480, 1560, 0, 1050, 1053, 1057, 1112, 0,
    369       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
    370  1.5.16.1  pgoyette 	/* 0x2e - 1440x900@60Hz RB */
    371       1.3  riastrad 	{ DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 88750, 1440, 1488,
    372       1.3  riastrad 		   1520, 1600, 0, 900, 903, 909, 926, 0,
    373       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
    374  1.5.16.1  pgoyette 	/* 0x2f - 1440x900@60Hz */
    375       1.3  riastrad 	{ DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 106500, 1440, 1520,
    376       1.3  riastrad 		   1672, 1904, 0, 900, 903, 909, 934, 0,
    377       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
    378  1.5.16.1  pgoyette 	/* 0x30 - 1440x900@75Hz */
    379       1.3  riastrad 	{ DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 136750, 1440, 1536,
    380       1.3  riastrad 		   1688, 1936, 0, 900, 903, 909, 942, 0,
    381       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
    382  1.5.16.1  pgoyette 	/* 0x31 - 1440x900@85Hz */
    383       1.3  riastrad 	{ DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 157000, 1440, 1544,
    384       1.3  riastrad 		   1696, 1952, 0, 900, 903, 909, 948, 0,
    385       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
    386  1.5.16.1  pgoyette 	/* 0x32 - 1440x900@120Hz RB */
    387       1.3  riastrad 	{ DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 182750, 1440, 1488,
    388       1.3  riastrad 		   1520, 1600, 0, 900, 903, 909, 953, 0,
    389       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
    390  1.5.16.1  pgoyette 	/* 0x53 - 1600x900@60Hz */
    391  1.5.16.1  pgoyette 	{ DRM_MODE("1600x900", DRM_MODE_TYPE_DRIVER, 108000, 1600, 1624,
    392  1.5.16.1  pgoyette 		   1704, 1800, 0, 900, 901, 904, 1000, 0,
    393  1.5.16.1  pgoyette 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
    394  1.5.16.1  pgoyette 	/* 0x33 - 1600x1200@60Hz */
    395       1.3  riastrad 	{ DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 162000, 1600, 1664,
    396       1.3  riastrad 		   1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
    397       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
    398  1.5.16.1  pgoyette 	/* 0x34 - 1600x1200@65Hz */
    399       1.3  riastrad 	{ DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 175500, 1600, 1664,
    400       1.3  riastrad 		   1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
    401       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
    402  1.5.16.1  pgoyette 	/* 0x35 - 1600x1200@70Hz */
    403       1.3  riastrad 	{ DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 189000, 1600, 1664,
    404       1.3  riastrad 		   1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
    405       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
    406  1.5.16.1  pgoyette 	/* 0x36 - 1600x1200@75Hz */
    407       1.3  riastrad 	{ DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 202500, 1600, 1664,
    408       1.3  riastrad 		   1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
    409       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
    410  1.5.16.1  pgoyette 	/* 0x37 - 1600x1200@85Hz */
    411       1.3  riastrad 	{ DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 229500, 1600, 1664,
    412       1.3  riastrad 		   1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
    413       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
    414  1.5.16.1  pgoyette 	/* 0x38 - 1600x1200@120Hz RB */
    415       1.3  riastrad 	{ DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 268250, 1600, 1648,
    416       1.3  riastrad 		   1680, 1760, 0, 1200, 1203, 1207, 1271, 0,
    417       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
    418  1.5.16.1  pgoyette 	/* 0x39 - 1680x1050@60Hz RB */
    419       1.3  riastrad 	{ DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 119000, 1680, 1728,
    420       1.3  riastrad 		   1760, 1840, 0, 1050, 1053, 1059, 1080, 0,
    421       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
    422  1.5.16.1  pgoyette 	/* 0x3a - 1680x1050@60Hz */
    423       1.3  riastrad 	{ DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 146250, 1680, 1784,
    424       1.3  riastrad 		   1960, 2240, 0, 1050, 1053, 1059, 1089, 0,
    425       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
    426  1.5.16.1  pgoyette 	/* 0x3b - 1680x1050@75Hz */
    427       1.3  riastrad 	{ DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 187000, 1680, 1800,
    428       1.3  riastrad 		   1976, 2272, 0, 1050, 1053, 1059, 1099, 0,
    429       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
    430  1.5.16.1  pgoyette 	/* 0x3c - 1680x1050@85Hz */
    431       1.3  riastrad 	{ DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 214750, 1680, 1808,
    432       1.3  riastrad 		   1984, 2288, 0, 1050, 1053, 1059, 1105, 0,
    433       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
    434  1.5.16.1  pgoyette 	/* 0x3d - 1680x1050@120Hz RB */
    435       1.3  riastrad 	{ DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 245500, 1680, 1728,
    436       1.3  riastrad 		   1760, 1840, 0, 1050, 1053, 1059, 1112, 0,
    437       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
    438  1.5.16.1  pgoyette 	/* 0x3e - 1792x1344@60Hz */
    439       1.3  riastrad 	{ DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 204750, 1792, 1920,
    440       1.3  riastrad 		   2120, 2448, 0, 1344, 1345, 1348, 1394, 0,
    441       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
    442  1.5.16.1  pgoyette 	/* 0x3f - 1792x1344@75Hz */
    443       1.3  riastrad 	{ DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 261000, 1792, 1888,
    444       1.3  riastrad 		   2104, 2456, 0, 1344, 1345, 1348, 1417, 0,
    445       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
    446  1.5.16.1  pgoyette 	/* 0x40 - 1792x1344@120Hz RB */
    447       1.3  riastrad 	{ DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 333250, 1792, 1840,
    448       1.3  riastrad 		   1872, 1952, 0, 1344, 1347, 1351, 1423, 0,
    449       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
    450  1.5.16.1  pgoyette 	/* 0x41 - 1856x1392@60Hz */
    451       1.3  riastrad 	{ DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 218250, 1856, 1952,
    452       1.3  riastrad 		   2176, 2528, 0, 1392, 1393, 1396, 1439, 0,
    453       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
    454  1.5.16.1  pgoyette 	/* 0x42 - 1856x1392@75Hz */
    455       1.3  riastrad 	{ DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 288000, 1856, 1984,
    456  1.5.16.1  pgoyette 		   2208, 2560, 0, 1392, 1393, 1396, 1500, 0,
    457       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
    458  1.5.16.1  pgoyette 	/* 0x43 - 1856x1392@120Hz RB */
    459       1.3  riastrad 	{ DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 356500, 1856, 1904,
    460       1.3  riastrad 		   1936, 2016, 0, 1392, 1395, 1399, 1474, 0,
    461       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
    462  1.5.16.1  pgoyette 	/* 0x52 - 1920x1080@60Hz */
    463  1.5.16.1  pgoyette 	{ DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
    464  1.5.16.1  pgoyette 		   2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
    465  1.5.16.1  pgoyette 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
    466  1.5.16.1  pgoyette 	/* 0x44 - 1920x1200@60Hz RB */
    467       1.3  riastrad 	{ DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 154000, 1920, 1968,
    468       1.3  riastrad 		   2000, 2080, 0, 1200, 1203, 1209, 1235, 0,
    469       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
    470  1.5.16.1  pgoyette 	/* 0x45 - 1920x1200@60Hz */
    471       1.3  riastrad 	{ DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 193250, 1920, 2056,
    472       1.3  riastrad 		   2256, 2592, 0, 1200, 1203, 1209, 1245, 0,
    473       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
    474  1.5.16.1  pgoyette 	/* 0x46 - 1920x1200@75Hz */
    475       1.3  riastrad 	{ DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 245250, 1920, 2056,
    476       1.3  riastrad 		   2264, 2608, 0, 1200, 1203, 1209, 1255, 0,
    477       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
    478  1.5.16.1  pgoyette 	/* 0x47 - 1920x1200@85Hz */
    479       1.3  riastrad 	{ DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 281250, 1920, 2064,
    480       1.3  riastrad 		   2272, 2624, 0, 1200, 1203, 1209, 1262, 0,
    481       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
    482  1.5.16.1  pgoyette 	/* 0x48 - 1920x1200@120Hz RB */
    483       1.3  riastrad 	{ DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 317000, 1920, 1968,
    484       1.3  riastrad 		   2000, 2080, 0, 1200, 1203, 1209, 1271, 0,
    485       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
    486  1.5.16.1  pgoyette 	/* 0x49 - 1920x1440@60Hz */
    487       1.3  riastrad 	{ DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 234000, 1920, 2048,
    488       1.3  riastrad 		   2256, 2600, 0, 1440, 1441, 1444, 1500, 0,
    489       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
    490  1.5.16.1  pgoyette 	/* 0x4a - 1920x1440@75Hz */
    491       1.3  riastrad 	{ DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2064,
    492       1.3  riastrad 		   2288, 2640, 0, 1440, 1441, 1444, 1500, 0,
    493       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
    494  1.5.16.1  pgoyette 	/* 0x4b - 1920x1440@120Hz RB */
    495       1.3  riastrad 	{ DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 380500, 1920, 1968,
    496       1.3  riastrad 		   2000, 2080, 0, 1440, 1443, 1447, 1525, 0,
    497       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
    498  1.5.16.1  pgoyette 	/* 0x54 - 2048x1152@60Hz */
    499  1.5.16.1  pgoyette 	{ DRM_MODE("2048x1152", DRM_MODE_TYPE_DRIVER, 162000, 2048, 2074,
    500  1.5.16.1  pgoyette 		   2154, 2250, 0, 1152, 1153, 1156, 1200, 0,
    501  1.5.16.1  pgoyette 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
    502  1.5.16.1  pgoyette 	/* 0x4c - 2560x1600@60Hz RB */
    503       1.3  riastrad 	{ DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 268500, 2560, 2608,
    504       1.3  riastrad 		   2640, 2720, 0, 1600, 1603, 1609, 1646, 0,
    505       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
    506  1.5.16.1  pgoyette 	/* 0x4d - 2560x1600@60Hz */
    507       1.3  riastrad 	{ DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 348500, 2560, 2752,
    508       1.3  riastrad 		   3032, 3504, 0, 1600, 1603, 1609, 1658, 0,
    509       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
    510  1.5.16.1  pgoyette 	/* 0x4e - 2560x1600@75Hz */
    511       1.3  riastrad 	{ DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 443250, 2560, 2768,
    512       1.3  riastrad 		   3048, 3536, 0, 1600, 1603, 1609, 1672, 0,
    513       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
    514  1.5.16.1  pgoyette 	/* 0x4f - 2560x1600@85Hz */
    515       1.3  riastrad 	{ DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 505250, 2560, 2768,
    516       1.3  riastrad 		   3048, 3536, 0, 1600, 1603, 1609, 1682, 0,
    517       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
    518  1.5.16.1  pgoyette 	/* 0x50 - 2560x1600@120Hz RB */
    519       1.3  riastrad 	{ DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 552750, 2560, 2608,
    520       1.3  riastrad 		   2640, 2720, 0, 1600, 1603, 1609, 1694, 0,
    521       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
    522  1.5.16.1  pgoyette 	/* 0x57 - 4096x2160@60Hz RB */
    523  1.5.16.1  pgoyette 	{ DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 556744, 4096, 4104,
    524  1.5.16.1  pgoyette 		   4136, 4176, 0, 2160, 2208, 2216, 2222, 0,
    525  1.5.16.1  pgoyette 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
    526  1.5.16.1  pgoyette 	/* 0x58 - 4096x2160 (at) 59.94Hz RB */
    527  1.5.16.1  pgoyette 	{ DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 556188, 4096, 4104,
    528  1.5.16.1  pgoyette 		   4136, 4176, 0, 2160, 2208, 2216, 2222, 0,
    529  1.5.16.1  pgoyette 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
    530       1.3  riastrad };
    531       1.3  riastrad 
    532       1.3  riastrad /*
    533       1.3  riastrad  * These more or less come from the DMT spec.  The 720x400 modes are
    534       1.3  riastrad  * inferred from historical 80x25 practice.  The 640x480@67 and 832x624@75
    535       1.3  riastrad  * modes are old-school Mac modes.  The EDID spec says the 1152x864@75 mode
    536       1.3  riastrad  * should be 1152x870, again for the Mac, but instead we use the x864 DMT
    537       1.3  riastrad  * mode.
    538       1.3  riastrad  *
    539       1.3  riastrad  * The DMT modes have been fact-checked; the rest are mild guesses.
    540       1.3  riastrad  */
    541       1.3  riastrad static const struct drm_display_mode edid_est_modes[] = {
    542       1.3  riastrad 	{ DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
    543       1.3  riastrad 		   968, 1056, 0, 600, 601, 605, 628, 0,
    544       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@60Hz */
    545       1.3  riastrad 	{ DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
    546       1.3  riastrad 		   896, 1024, 0, 600, 601, 603,  625, 0,
    547       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@56Hz */
    548       1.3  riastrad 	{ DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
    549       1.3  riastrad 		   720, 840, 0, 480, 481, 484, 500, 0,
    550       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@75Hz */
    551       1.3  riastrad 	{ DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
    552       1.3  riastrad 		   704,  832, 0, 480, 489, 491, 520, 0,
    553       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@72Hz */
    554       1.3  riastrad 	{ DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 30240, 640, 704,
    555       1.3  riastrad 		   768,  864, 0, 480, 483, 486, 525, 0,
    556       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@67Hz */
    557       1.3  riastrad 	{ DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25200, 640, 656,
    558       1.3  riastrad 		   752, 800, 0, 480, 490, 492, 525, 0,
    559       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@60Hz */
    560       1.3  riastrad 	{ DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 738,
    561       1.3  riastrad 		   846, 900, 0, 400, 421, 423,  449, 0,
    562       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 720x400@88Hz */
    563       1.3  riastrad 	{ DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 28320, 720, 738,
    564       1.3  riastrad 		   846,  900, 0, 400, 412, 414, 449, 0,
    565       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 720x400@70Hz */
    566       1.3  riastrad 	{ DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
    567       1.3  riastrad 		   1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
    568       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1280x1024@75Hz */
    569       1.3  riastrad 	{ DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78800, 1024, 1040,
    570       1.3  riastrad 		   1136, 1312, 0,  768, 769, 772, 800, 0,
    571       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1024x768@75Hz */
    572       1.3  riastrad 	{ DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
    573       1.3  riastrad 		   1184, 1328, 0,  768, 771, 777, 806, 0,
    574       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@70Hz */
    575       1.3  riastrad 	{ DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
    576       1.3  riastrad 		   1184, 1344, 0,  768, 771, 777, 806, 0,
    577       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@60Hz */
    578       1.3  riastrad 	{ DRM_MODE("1024x768i", DRM_MODE_TYPE_DRIVER,44900, 1024, 1032,
    579       1.3  riastrad 		   1208, 1264, 0, 768, 768, 776, 817, 0,
    580       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_INTERLACE) }, /* 1024x768@43Hz */
    581       1.3  riastrad 	{ DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 57284, 832, 864,
    582       1.3  riastrad 		   928, 1152, 0, 624, 625, 628, 667, 0,
    583       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 832x624@75Hz */
    584       1.3  riastrad 	{ DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
    585       1.3  riastrad 		   896, 1056, 0, 600, 601, 604,  625, 0,
    586       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@75Hz */
    587       1.3  riastrad 	{ DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
    588       1.3  riastrad 		   976, 1040, 0, 600, 637, 643, 666, 0,
    589       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@72Hz */
    590       1.3  riastrad 	{ DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
    591       1.3  riastrad 		   1344, 1600, 0,  864, 865, 868, 900, 0,
    592       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1152x864@75Hz */
    593       1.3  riastrad };
    594       1.3  riastrad 
    595       1.3  riastrad struct minimode {
    596       1.3  riastrad 	short w;
    597       1.3  riastrad 	short h;
    598       1.3  riastrad 	short r;
    599       1.3  riastrad 	short rb;
    600       1.3  riastrad };
    601       1.3  riastrad 
    602       1.3  riastrad static const struct minimode est3_modes[] = {
    603       1.3  riastrad 	/* byte 6 */
    604       1.3  riastrad 	{ 640, 350, 85, 0 },
    605       1.3  riastrad 	{ 640, 400, 85, 0 },
    606       1.3  riastrad 	{ 720, 400, 85, 0 },
    607       1.3  riastrad 	{ 640, 480, 85, 0 },
    608       1.3  riastrad 	{ 848, 480, 60, 0 },
    609       1.3  riastrad 	{ 800, 600, 85, 0 },
    610       1.3  riastrad 	{ 1024, 768, 85, 0 },
    611       1.3  riastrad 	{ 1152, 864, 75, 0 },
    612       1.3  riastrad 	/* byte 7 */
    613       1.3  riastrad 	{ 1280, 768, 60, 1 },
    614       1.3  riastrad 	{ 1280, 768, 60, 0 },
    615       1.3  riastrad 	{ 1280, 768, 75, 0 },
    616       1.3  riastrad 	{ 1280, 768, 85, 0 },
    617       1.3  riastrad 	{ 1280, 960, 60, 0 },
    618       1.3  riastrad 	{ 1280, 960, 85, 0 },
    619       1.3  riastrad 	{ 1280, 1024, 60, 0 },
    620       1.3  riastrad 	{ 1280, 1024, 85, 0 },
    621       1.3  riastrad 	/* byte 8 */
    622       1.3  riastrad 	{ 1360, 768, 60, 0 },
    623       1.3  riastrad 	{ 1440, 900, 60, 1 },
    624       1.3  riastrad 	{ 1440, 900, 60, 0 },
    625       1.3  riastrad 	{ 1440, 900, 75, 0 },
    626       1.3  riastrad 	{ 1440, 900, 85, 0 },
    627       1.3  riastrad 	{ 1400, 1050, 60, 1 },
    628       1.3  riastrad 	{ 1400, 1050, 60, 0 },
    629       1.3  riastrad 	{ 1400, 1050, 75, 0 },
    630       1.3  riastrad 	/* byte 9 */
    631       1.3  riastrad 	{ 1400, 1050, 85, 0 },
    632       1.3  riastrad 	{ 1680, 1050, 60, 1 },
    633       1.3  riastrad 	{ 1680, 1050, 60, 0 },
    634       1.3  riastrad 	{ 1680, 1050, 75, 0 },
    635       1.3  riastrad 	{ 1680, 1050, 85, 0 },
    636       1.3  riastrad 	{ 1600, 1200, 60, 0 },
    637       1.3  riastrad 	{ 1600, 1200, 65, 0 },
    638       1.3  riastrad 	{ 1600, 1200, 70, 0 },
    639       1.3  riastrad 	/* byte 10 */
    640       1.3  riastrad 	{ 1600, 1200, 75, 0 },
    641       1.3  riastrad 	{ 1600, 1200, 85, 0 },
    642       1.3  riastrad 	{ 1792, 1344, 60, 0 },
    643       1.3  riastrad 	{ 1792, 1344, 75, 0 },
    644       1.3  riastrad 	{ 1856, 1392, 60, 0 },
    645       1.3  riastrad 	{ 1856, 1392, 75, 0 },
    646       1.3  riastrad 	{ 1920, 1200, 60, 1 },
    647       1.3  riastrad 	{ 1920, 1200, 60, 0 },
    648       1.3  riastrad 	/* byte 11 */
    649       1.3  riastrad 	{ 1920, 1200, 75, 0 },
    650       1.3  riastrad 	{ 1920, 1200, 85, 0 },
    651       1.3  riastrad 	{ 1920, 1440, 60, 0 },
    652       1.3  riastrad 	{ 1920, 1440, 75, 0 },
    653       1.3  riastrad };
    654       1.3  riastrad 
    655       1.3  riastrad static const struct minimode extra_modes[] = {
    656       1.3  riastrad 	{ 1024, 576,  60, 0 },
    657       1.3  riastrad 	{ 1366, 768,  60, 0 },
    658       1.3  riastrad 	{ 1600, 900,  60, 0 },
    659       1.3  riastrad 	{ 1680, 945,  60, 0 },
    660       1.3  riastrad 	{ 1920, 1080, 60, 0 },
    661       1.3  riastrad 	{ 2048, 1152, 60, 0 },
    662       1.3  riastrad 	{ 2048, 1536, 60, 0 },
    663       1.3  riastrad };
    664       1.3  riastrad 
    665       1.3  riastrad /*
    666       1.3  riastrad  * Probably taken from CEA-861 spec.
    667       1.3  riastrad  * This table is converted from xorg's hw/xfree86/modes/xf86EdidModes.c.
    668       1.3  riastrad  */
    669       1.3  riastrad static const struct drm_display_mode edid_cea_modes[] = {
    670       1.3  riastrad 	/* 1 - 640x480@60Hz */
    671       1.3  riastrad 	{ DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
    672       1.3  riastrad 		   752, 800, 0, 480, 490, 492, 525, 0,
    673       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
    674       1.3  riastrad 	  .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
    675       1.3  riastrad 	/* 2 - 720x480@60Hz */
    676       1.3  riastrad 	{ DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 27000, 720, 736,
    677       1.3  riastrad 		   798, 858, 0, 480, 489, 495, 525, 0,
    678       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
    679       1.3  riastrad 	  .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
    680       1.3  riastrad 	/* 3 - 720x480@60Hz */
    681       1.3  riastrad 	{ DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 27000, 720, 736,
    682       1.3  riastrad 		   798, 858, 0, 480, 489, 495, 525, 0,
    683       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
    684       1.3  riastrad 	  .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    685       1.3  riastrad 	/* 4 - 1280x720@60Hz */
    686       1.3  riastrad 	{ DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
    687       1.3  riastrad 		   1430, 1650, 0, 720, 725, 730, 750, 0,
    688       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
    689       1.3  riastrad 	  .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    690       1.3  riastrad 	/* 5 - 1920x1080i@60Hz */
    691       1.3  riastrad 	{ DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
    692       1.3  riastrad 		   2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
    693       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
    694       1.3  riastrad 			DRM_MODE_FLAG_INTERLACE),
    695       1.3  riastrad 	  .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    696  1.5.16.1  pgoyette 	/* 6 - 720(1440)x480i@60Hz */
    697  1.5.16.1  pgoyette 	{ DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
    698  1.5.16.1  pgoyette 		   801, 858, 0, 480, 488, 494, 525, 0,
    699       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
    700       1.3  riastrad 			DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
    701       1.3  riastrad 	  .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
    702  1.5.16.1  pgoyette 	/* 7 - 720(1440)x480i@60Hz */
    703  1.5.16.1  pgoyette 	{ DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
    704  1.5.16.1  pgoyette 		   801, 858, 0, 480, 488, 494, 525, 0,
    705       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
    706       1.3  riastrad 			DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
    707       1.3  riastrad 	  .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    708  1.5.16.1  pgoyette 	/* 8 - 720(1440)x240@60Hz */
    709  1.5.16.1  pgoyette 	{ DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
    710  1.5.16.1  pgoyette 		   801, 858, 0, 240, 244, 247, 262, 0,
    711       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
    712       1.3  riastrad 			DRM_MODE_FLAG_DBLCLK),
    713       1.3  riastrad 	  .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
    714  1.5.16.1  pgoyette 	/* 9 - 720(1440)x240@60Hz */
    715  1.5.16.1  pgoyette 	{ DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
    716  1.5.16.1  pgoyette 		   801, 858, 0, 240, 244, 247, 262, 0,
    717       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
    718       1.3  riastrad 			DRM_MODE_FLAG_DBLCLK),
    719       1.3  riastrad 	  .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    720       1.3  riastrad 	/* 10 - 2880x480i@60Hz */
    721       1.3  riastrad 	{ DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
    722       1.3  riastrad 		   3204, 3432, 0, 480, 488, 494, 525, 0,
    723       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
    724       1.3  riastrad 			DRM_MODE_FLAG_INTERLACE),
    725       1.3  riastrad 	  .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
    726       1.3  riastrad 	/* 11 - 2880x480i@60Hz */
    727       1.3  riastrad 	{ DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
    728       1.3  riastrad 		   3204, 3432, 0, 480, 488, 494, 525, 0,
    729       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
    730       1.3  riastrad 			DRM_MODE_FLAG_INTERLACE),
    731       1.3  riastrad 	  .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    732       1.3  riastrad 	/* 12 - 2880x240@60Hz */
    733       1.3  riastrad 	{ DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
    734       1.3  riastrad 		   3204, 3432, 0, 240, 244, 247, 262, 0,
    735       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
    736       1.3  riastrad 	  .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
    737       1.3  riastrad 	/* 13 - 2880x240@60Hz */
    738       1.3  riastrad 	{ DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
    739       1.3  riastrad 		   3204, 3432, 0, 240, 244, 247, 262, 0,
    740       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
    741       1.3  riastrad 	  .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    742       1.3  riastrad 	/* 14 - 1440x480@60Hz */
    743       1.3  riastrad 	{ DRM_MODE("1440x480", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1472,
    744       1.3  riastrad 		   1596, 1716, 0, 480, 489, 495, 525, 0,
    745       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
    746       1.3  riastrad 	  .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
    747       1.3  riastrad 	/* 15 - 1440x480@60Hz */
    748       1.3  riastrad 	{ DRM_MODE("1440x480", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1472,
    749       1.3  riastrad 		   1596, 1716, 0, 480, 489, 495, 525, 0,
    750       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
    751       1.3  riastrad 	  .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    752       1.3  riastrad 	/* 16 - 1920x1080@60Hz */
    753       1.3  riastrad 	{ DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
    754       1.3  riastrad 		   2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
    755       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
    756       1.3  riastrad 	  .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    757       1.3  riastrad 	/* 17 - 720x576@50Hz */
    758       1.3  riastrad 	{ DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
    759       1.3  riastrad 		   796, 864, 0, 576, 581, 586, 625, 0,
    760       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
    761       1.3  riastrad 	  .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
    762       1.3  riastrad 	/* 18 - 720x576@50Hz */
    763       1.3  riastrad 	{ DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
    764       1.3  riastrad 		   796, 864, 0, 576, 581, 586, 625, 0,
    765       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
    766       1.3  riastrad 	  .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    767       1.3  riastrad 	/* 19 - 1280x720@50Hz */
    768       1.3  riastrad 	{ DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1720,
    769       1.3  riastrad 		   1760, 1980, 0, 720, 725, 730, 750, 0,
    770       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
    771       1.3  riastrad 	  .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    772       1.3  riastrad 	/* 20 - 1920x1080i@50Hz */
    773       1.3  riastrad 	{ DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
    774       1.3  riastrad 		   2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
    775       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
    776       1.3  riastrad 			DRM_MODE_FLAG_INTERLACE),
    777       1.3  riastrad 	  .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    778  1.5.16.1  pgoyette 	/* 21 - 720(1440)x576i@50Hz */
    779  1.5.16.1  pgoyette 	{ DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
    780  1.5.16.1  pgoyette 		   795, 864, 0, 576, 580, 586, 625, 0,
    781       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
    782       1.3  riastrad 			DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
    783       1.3  riastrad 	  .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
    784  1.5.16.1  pgoyette 	/* 22 - 720(1440)x576i@50Hz */
    785  1.5.16.1  pgoyette 	{ DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
    786  1.5.16.1  pgoyette 		   795, 864, 0, 576, 580, 586, 625, 0,
    787       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
    788       1.3  riastrad 			DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
    789       1.3  riastrad 	  .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    790  1.5.16.1  pgoyette 	/* 23 - 720(1440)x288@50Hz */
    791  1.5.16.1  pgoyette 	{ DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
    792  1.5.16.1  pgoyette 		   795, 864, 0, 288, 290, 293, 312, 0,
    793       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
    794       1.3  riastrad 			DRM_MODE_FLAG_DBLCLK),
    795       1.3  riastrad 	  .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
    796  1.5.16.1  pgoyette 	/* 24 - 720(1440)x288@50Hz */
    797  1.5.16.1  pgoyette 	{ DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
    798  1.5.16.1  pgoyette 		   795, 864, 0, 288, 290, 293, 312, 0,
    799       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
    800       1.3  riastrad 			DRM_MODE_FLAG_DBLCLK),
    801       1.3  riastrad 	  .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    802       1.3  riastrad 	/* 25 - 2880x576i@50Hz */
    803       1.3  riastrad 	{ DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
    804       1.3  riastrad 		   3180, 3456, 0, 576, 580, 586, 625, 0,
    805       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
    806       1.3  riastrad 			DRM_MODE_FLAG_INTERLACE),
    807       1.3  riastrad 	  .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
    808       1.3  riastrad 	/* 26 - 2880x576i@50Hz */
    809       1.3  riastrad 	{ DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
    810       1.3  riastrad 		   3180, 3456, 0, 576, 580, 586, 625, 0,
    811       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
    812       1.3  riastrad 			DRM_MODE_FLAG_INTERLACE),
    813       1.3  riastrad 	  .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    814       1.3  riastrad 	/* 27 - 2880x288@50Hz */
    815       1.3  riastrad 	{ DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
    816       1.3  riastrad 		   3180, 3456, 0, 288, 290, 293, 312, 0,
    817       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
    818       1.3  riastrad 	  .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
    819       1.3  riastrad 	/* 28 - 2880x288@50Hz */
    820       1.3  riastrad 	{ DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
    821       1.3  riastrad 		   3180, 3456, 0, 288, 290, 293, 312, 0,
    822       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
    823       1.3  riastrad 	  .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    824       1.3  riastrad 	/* 29 - 1440x576@50Hz */
    825       1.3  riastrad 	{ DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1464,
    826       1.3  riastrad 		   1592, 1728, 0, 576, 581, 586, 625, 0,
    827       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
    828       1.3  riastrad 	  .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
    829       1.3  riastrad 	/* 30 - 1440x576@50Hz */
    830       1.3  riastrad 	{ DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1464,
    831       1.3  riastrad 		   1592, 1728, 0, 576, 581, 586, 625, 0,
    832       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
    833       1.3  riastrad 	  .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    834       1.3  riastrad 	/* 31 - 1920x1080@50Hz */
    835       1.3  riastrad 	{ DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
    836       1.3  riastrad 		   2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
    837       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
    838       1.3  riastrad 	  .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    839       1.3  riastrad 	/* 32 - 1920x1080@24Hz */
    840       1.3  riastrad 	{ DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2558,
    841       1.3  riastrad 		   2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
    842       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
    843       1.3  riastrad 	  .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    844       1.3  riastrad 	/* 33 - 1920x1080@25Hz */
    845       1.3  riastrad 	{ DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
    846       1.3  riastrad 		   2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
    847       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
    848       1.3  riastrad 	  .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    849       1.3  riastrad 	/* 34 - 1920x1080@30Hz */
    850       1.3  riastrad 	{ DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
    851       1.3  riastrad 		   2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
    852       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
    853       1.3  riastrad 	  .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    854       1.3  riastrad 	/* 35 - 2880x480@60Hz */
    855       1.3  riastrad 	{ DRM_MODE("2880x480", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2944,
    856       1.3  riastrad 		   3192, 3432, 0, 480, 489, 495, 525, 0,
    857       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
    858       1.3  riastrad 	  .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
    859       1.3  riastrad 	/* 36 - 2880x480@60Hz */
    860       1.3  riastrad 	{ DRM_MODE("2880x480", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2944,
    861       1.3  riastrad 		   3192, 3432, 0, 480, 489, 495, 525, 0,
    862       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
    863       1.3  riastrad 	  .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    864       1.3  riastrad 	/* 37 - 2880x576@50Hz */
    865       1.3  riastrad 	{ DRM_MODE("2880x576", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2928,
    866       1.3  riastrad 		   3184, 3456, 0, 576, 581, 586, 625, 0,
    867       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
    868       1.3  riastrad 	  .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
    869       1.3  riastrad 	/* 38 - 2880x576@50Hz */
    870       1.3  riastrad 	{ DRM_MODE("2880x576", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2928,
    871       1.3  riastrad 		   3184, 3456, 0, 576, 581, 586, 625, 0,
    872       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
    873       1.3  riastrad 	  .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    874       1.3  riastrad 	/* 39 - 1920x1080i@50Hz */
    875       1.3  riastrad 	{ DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 72000, 1920, 1952,
    876       1.3  riastrad 		   2120, 2304, 0, 1080, 1126, 1136, 1250, 0,
    877       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC |
    878       1.3  riastrad 			DRM_MODE_FLAG_INTERLACE),
    879       1.3  riastrad 	  .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    880       1.3  riastrad 	/* 40 - 1920x1080i@100Hz */
    881       1.3  riastrad 	{ DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
    882       1.3  riastrad 		   2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
    883       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
    884       1.3  riastrad 			DRM_MODE_FLAG_INTERLACE),
    885       1.3  riastrad 	  .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    886       1.3  riastrad 	/* 41 - 1280x720@100Hz */
    887       1.3  riastrad 	{ DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1720,
    888       1.3  riastrad 		   1760, 1980, 0, 720, 725, 730, 750, 0,
    889       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
    890       1.3  riastrad 	  .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    891       1.3  riastrad 	/* 42 - 720x576@100Hz */
    892       1.3  riastrad 	{ DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
    893       1.3  riastrad 		   796, 864, 0, 576, 581, 586, 625, 0,
    894       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
    895       1.3  riastrad 	  .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
    896       1.3  riastrad 	/* 43 - 720x576@100Hz */
    897       1.3  riastrad 	{ DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
    898       1.3  riastrad 		   796, 864, 0, 576, 581, 586, 625, 0,
    899       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
    900       1.3  riastrad 	  .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    901  1.5.16.1  pgoyette 	/* 44 - 720(1440)x576i@100Hz */
    902  1.5.16.1  pgoyette 	{ DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
    903  1.5.16.1  pgoyette 		   795, 864, 0, 576, 580, 586, 625, 0,
    904       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
    905  1.5.16.1  pgoyette 			DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
    906       1.3  riastrad 	  .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
    907  1.5.16.1  pgoyette 	/* 45 - 720(1440)x576i@100Hz */
    908  1.5.16.1  pgoyette 	{ DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
    909  1.5.16.1  pgoyette 		   795, 864, 0, 576, 580, 586, 625, 0,
    910       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
    911  1.5.16.1  pgoyette 			DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
    912       1.3  riastrad 	  .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    913       1.3  riastrad 	/* 46 - 1920x1080i@120Hz */
    914       1.3  riastrad 	{ DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
    915       1.3  riastrad 		   2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
    916       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
    917       1.3  riastrad 			DRM_MODE_FLAG_INTERLACE),
    918       1.3  riastrad 	  .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    919       1.3  riastrad 	/* 47 - 1280x720@120Hz */
    920       1.3  riastrad 	{ DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1390,
    921       1.3  riastrad 		   1430, 1650, 0, 720, 725, 730, 750, 0,
    922       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
    923       1.3  riastrad 	  .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    924       1.3  riastrad 	/* 48 - 720x480@120Hz */
    925       1.3  riastrad 	{ DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 54000, 720, 736,
    926       1.3  riastrad 		   798, 858, 0, 480, 489, 495, 525, 0,
    927       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
    928       1.3  riastrad 	  .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
    929       1.3  riastrad 	/* 49 - 720x480@120Hz */
    930       1.3  riastrad 	{ DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 54000, 720, 736,
    931       1.3  riastrad 		   798, 858, 0, 480, 489, 495, 525, 0,
    932       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
    933       1.3  riastrad 	  .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    934  1.5.16.1  pgoyette 	/* 50 - 720(1440)x480i@120Hz */
    935  1.5.16.1  pgoyette 	{ DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 27000, 720, 739,
    936  1.5.16.1  pgoyette 		   801, 858, 0, 480, 488, 494, 525, 0,
    937       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
    938       1.3  riastrad 			DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
    939       1.3  riastrad 	  .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
    940  1.5.16.1  pgoyette 	/* 51 - 720(1440)x480i@120Hz */
    941  1.5.16.1  pgoyette 	{ DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 27000, 720, 739,
    942  1.5.16.1  pgoyette 		   801, 858, 0, 480, 488, 494, 525, 0,
    943       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
    944       1.3  riastrad 			DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
    945       1.3  riastrad 	  .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    946       1.3  riastrad 	/* 52 - 720x576@200Hz */
    947       1.3  riastrad 	{ DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 108000, 720, 732,
    948       1.3  riastrad 		   796, 864, 0, 576, 581, 586, 625, 0,
    949       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
    950       1.3  riastrad 	  .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
    951       1.3  riastrad 	/* 53 - 720x576@200Hz */
    952       1.3  riastrad 	{ DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 108000, 720, 732,
    953       1.3  riastrad 		   796, 864, 0, 576, 581, 586, 625, 0,
    954       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
    955       1.3  riastrad 	  .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    956  1.5.16.1  pgoyette 	/* 54 - 720(1440)x576i@200Hz */
    957  1.5.16.1  pgoyette 	{ DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
    958  1.5.16.1  pgoyette 		   795, 864, 0, 576, 580, 586, 625, 0,
    959       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
    960       1.3  riastrad 			DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
    961       1.3  riastrad 	  .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
    962  1.5.16.1  pgoyette 	/* 55 - 720(1440)x576i@200Hz */
    963  1.5.16.1  pgoyette 	{ DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
    964  1.5.16.1  pgoyette 		   795, 864, 0, 576, 580, 586, 625, 0,
    965       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
    966       1.3  riastrad 			DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
    967       1.3  riastrad 	  .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    968       1.3  riastrad 	/* 56 - 720x480@240Hz */
    969       1.3  riastrad 	{ DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 108000, 720, 736,
    970       1.3  riastrad 		   798, 858, 0, 480, 489, 495, 525, 0,
    971       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
    972       1.3  riastrad 	  .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
    973       1.3  riastrad 	/* 57 - 720x480@240Hz */
    974       1.3  riastrad 	{ DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 108000, 720, 736,
    975       1.3  riastrad 		   798, 858, 0, 480, 489, 495, 525, 0,
    976       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
    977       1.3  riastrad 	  .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    978  1.5.16.1  pgoyette 	/* 58 - 720(1440)x480i@240 */
    979  1.5.16.1  pgoyette 	{ DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 54000, 720, 739,
    980  1.5.16.1  pgoyette 		   801, 858, 0, 480, 488, 494, 525, 0,
    981       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
    982       1.3  riastrad 			DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
    983       1.3  riastrad 	  .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
    984  1.5.16.1  pgoyette 	/* 59 - 720(1440)x480i@240 */
    985  1.5.16.1  pgoyette 	{ DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 54000, 720, 739,
    986  1.5.16.1  pgoyette 		   801, 858, 0, 480, 488, 494, 525, 0,
    987       1.3  riastrad 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
    988       1.3  riastrad 			DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
    989       1.3  riastrad 	  .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    990       1.3  riastrad 	/* 60 - 1280x720@24Hz */
    991       1.3  riastrad 	{ DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 59400, 1280, 3040,
    992       1.3  riastrad 		   3080, 3300, 0, 720, 725, 730, 750, 0,
    993       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
    994       1.3  riastrad 	  .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
    995       1.3  riastrad 	/* 61 - 1280x720@25Hz */
    996       1.3  riastrad 	{ DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3700,
    997       1.3  riastrad 		   3740, 3960, 0, 720, 725, 730, 750, 0,
    998       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
    999       1.3  riastrad 	  .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
   1000       1.3  riastrad 	/* 62 - 1280x720@30Hz */
   1001       1.3  riastrad 	{ DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3040,
   1002       1.3  riastrad 		   3080, 3300, 0, 720, 725, 730, 750, 0,
   1003       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
   1004       1.3  riastrad 	  .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
   1005       1.3  riastrad 	/* 63 - 1920x1080@120Hz */
   1006       1.3  riastrad 	{ DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2008,
   1007       1.3  riastrad 		   2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
   1008       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
   1009       1.3  riastrad 	 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
   1010       1.3  riastrad 	/* 64 - 1920x1080@100Hz */
   1011       1.3  riastrad 	{ DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2448,
   1012       1.3  riastrad 		   2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
   1013       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
   1014       1.3  riastrad 	 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
   1015       1.3  riastrad };
   1016       1.3  riastrad 
   1017       1.3  riastrad /*
   1018       1.3  riastrad  * HDMI 1.4 4k modes.
   1019       1.3  riastrad  */
   1020       1.3  riastrad static const struct drm_display_mode edid_4k_modes[] = {
   1021       1.3  riastrad 	/* 1 - 3840x2160@30Hz */
   1022       1.3  riastrad 	{ DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
   1023       1.3  riastrad 		   3840, 4016, 4104, 4400, 0,
   1024       1.3  riastrad 		   2160, 2168, 2178, 2250, 0,
   1025       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
   1026       1.3  riastrad 	  .vrefresh = 30, },
   1027       1.3  riastrad 	/* 2 - 3840x2160@25Hz */
   1028       1.3  riastrad 	{ DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
   1029       1.3  riastrad 		   3840, 4896, 4984, 5280, 0,
   1030       1.3  riastrad 		   2160, 2168, 2178, 2250, 0,
   1031       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
   1032       1.3  riastrad 	  .vrefresh = 25, },
   1033       1.3  riastrad 	/* 3 - 3840x2160@24Hz */
   1034       1.3  riastrad 	{ DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
   1035       1.3  riastrad 		   3840, 5116, 5204, 5500, 0,
   1036       1.3  riastrad 		   2160, 2168, 2178, 2250, 0,
   1037       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
   1038       1.3  riastrad 	  .vrefresh = 24, },
   1039       1.3  riastrad 	/* 4 - 4096x2160@24Hz (SMPTE) */
   1040       1.3  riastrad 	{ DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000,
   1041       1.3  riastrad 		   4096, 5116, 5204, 5500, 0,
   1042       1.3  riastrad 		   2160, 2168, 2178, 2250, 0,
   1043       1.3  riastrad 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
   1044       1.3  riastrad 	  .vrefresh = 24, },
   1045       1.1  riastrad };
   1046       1.1  riastrad 
   1047       1.1  riastrad /*** DDC fetch and block validation ***/
   1048       1.1  riastrad 
   1049       1.1  riastrad static const u8 edid_header[] = {
   1050       1.1  riastrad 	0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00
   1051       1.1  riastrad };
   1052       1.1  riastrad 
   1053  1.5.16.1  pgoyette /**
   1054  1.5.16.1  pgoyette  * drm_edid_header_is_valid - sanity check the header of the base EDID block
   1055  1.5.16.1  pgoyette  * @raw_edid: pointer to raw base EDID block
   1056  1.5.16.1  pgoyette  *
   1057  1.5.16.1  pgoyette  * Sanity check the header of the base EDID block.
   1058  1.5.16.1  pgoyette  *
   1059  1.5.16.1  pgoyette  * Return: 8 if the header is perfect, down to 0 if it's totally wrong.
   1060       1.1  riastrad  */
   1061       1.1  riastrad int drm_edid_header_is_valid(const u8 *raw_edid)
   1062       1.1  riastrad {
   1063       1.1  riastrad 	int i, score = 0;
   1064       1.1  riastrad 
   1065       1.1  riastrad 	for (i = 0; i < sizeof(edid_header); i++)
   1066       1.1  riastrad 		if (raw_edid[i] == edid_header[i])
   1067       1.1  riastrad 			score++;
   1068       1.1  riastrad 
   1069       1.1  riastrad 	return score;
   1070       1.1  riastrad }
   1071       1.1  riastrad EXPORT_SYMBOL(drm_edid_header_is_valid);
   1072       1.1  riastrad 
   1073       1.1  riastrad static int edid_fixup __read_mostly = 6;
   1074       1.1  riastrad module_param_named(edid_fixup, edid_fixup, int, 0400);
   1075       1.1  riastrad MODULE_PARM_DESC(edid_fixup,
   1076       1.1  riastrad 		 "Minimum number of valid EDID header bytes (0-8, default 6)");
   1077       1.1  riastrad 
   1078  1.5.16.1  pgoyette static void drm_get_displayid(struct drm_connector *connector,
   1079  1.5.16.1  pgoyette 			      struct edid *edid);
   1080  1.5.16.1  pgoyette 
   1081  1.5.16.1  pgoyette static int drm_edid_block_checksum(const u8 *raw_edid)
   1082       1.1  riastrad {
   1083       1.1  riastrad 	int i;
   1084       1.1  riastrad 	u8 csum = 0;
   1085  1.5.16.1  pgoyette 	for (i = 0; i < EDID_LENGTH; i++)
   1086  1.5.16.1  pgoyette 		csum += raw_edid[i];
   1087  1.5.16.1  pgoyette 
   1088  1.5.16.1  pgoyette 	return csum;
   1089  1.5.16.1  pgoyette }
   1090  1.5.16.1  pgoyette 
   1091  1.5.16.1  pgoyette static bool drm_edid_is_zero(const u8 *in_edid, int length)
   1092  1.5.16.1  pgoyette {
   1093  1.5.16.1  pgoyette 	if (memchr_inv(in_edid, 0, length))
   1094  1.5.16.1  pgoyette 		return false;
   1095  1.5.16.1  pgoyette 
   1096  1.5.16.1  pgoyette 	return true;
   1097  1.5.16.1  pgoyette }
   1098  1.5.16.1  pgoyette 
   1099  1.5.16.1  pgoyette /**
   1100  1.5.16.1  pgoyette  * drm_edid_block_valid - Sanity check the EDID block (base or extension)
   1101  1.5.16.1  pgoyette  * @raw_edid: pointer to raw EDID block
   1102  1.5.16.1  pgoyette  * @block: type of block to validate (0 for base, extension otherwise)
   1103  1.5.16.1  pgoyette  * @print_bad_edid: if true, dump bad EDID blocks to the console
   1104  1.5.16.1  pgoyette  * @edid_corrupt: if true, the header or checksum is invalid
   1105  1.5.16.1  pgoyette  *
   1106  1.5.16.1  pgoyette  * Validate a base or extension EDID block and optionally dump bad blocks to
   1107  1.5.16.1  pgoyette  * the console.
   1108  1.5.16.1  pgoyette  *
   1109  1.5.16.1  pgoyette  * Return: True if the block is valid, false otherwise.
   1110  1.5.16.1  pgoyette  */
   1111  1.5.16.1  pgoyette bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
   1112  1.5.16.1  pgoyette 			  bool *edid_corrupt)
   1113  1.5.16.1  pgoyette {
   1114  1.5.16.1  pgoyette 	u8 csum;
   1115       1.1  riastrad 	struct edid *edid = (struct edid *)raw_edid;
   1116       1.1  riastrad 
   1117       1.3  riastrad 	if (WARN_ON(!raw_edid))
   1118       1.3  riastrad 		return false;
   1119       1.3  riastrad 
   1120       1.1  riastrad 	if (edid_fixup > 8 || edid_fixup < 0)
   1121       1.1  riastrad 		edid_fixup = 6;
   1122       1.1  riastrad 
   1123       1.1  riastrad 	if (block == 0) {
   1124       1.1  riastrad 		int score = drm_edid_header_is_valid(raw_edid);
   1125  1.5.16.1  pgoyette 		if (score == 8) {
   1126  1.5.16.1  pgoyette 			if (edid_corrupt)
   1127  1.5.16.1  pgoyette 				*edid_corrupt = false;
   1128  1.5.16.1  pgoyette 		} else if (score >= edid_fixup) {
   1129  1.5.16.1  pgoyette 			/* Displayport Link CTS Core 1.2 rev1.1 test 4.2.2.6
   1130  1.5.16.1  pgoyette 			 * The corrupt flag needs to be set here otherwise, the
   1131  1.5.16.1  pgoyette 			 * fix-up code here will correct the problem, the
   1132  1.5.16.1  pgoyette 			 * checksum is correct and the test fails
   1133  1.5.16.1  pgoyette 			 */
   1134  1.5.16.1  pgoyette 			if (edid_corrupt)
   1135  1.5.16.1  pgoyette 				*edid_corrupt = true;
   1136       1.1  riastrad 			DRM_DEBUG("Fixing EDID header, your hardware may be failing\n");
   1137       1.1  riastrad 			memcpy(raw_edid, edid_header, sizeof(edid_header));
   1138       1.1  riastrad 		} else {
   1139  1.5.16.1  pgoyette 			if (edid_corrupt)
   1140  1.5.16.1  pgoyette 				*edid_corrupt = true;
   1141       1.1  riastrad 			goto bad;
   1142       1.1  riastrad 		}
   1143       1.1  riastrad 	}
   1144       1.1  riastrad 
   1145  1.5.16.1  pgoyette 	csum = drm_edid_block_checksum(raw_edid);
   1146       1.1  riastrad 	if (csum) {
   1147       1.1  riastrad 		if (print_bad_edid) {
   1148       1.1  riastrad 			DRM_ERROR("EDID checksum is invalid, remainder is %d\n", csum);
   1149       1.1  riastrad 		}
   1150       1.1  riastrad 
   1151  1.5.16.1  pgoyette 		if (edid_corrupt)
   1152  1.5.16.1  pgoyette 			*edid_corrupt = true;
   1153  1.5.16.1  pgoyette 
   1154       1.1  riastrad 		/* allow CEA to slide through, switches mangle this */
   1155       1.1  riastrad 		if (raw_edid[0] != 0x02)
   1156       1.1  riastrad 			goto bad;
   1157       1.1  riastrad 	}
   1158       1.1  riastrad 
   1159       1.1  riastrad 	/* per-block-type checks */
   1160       1.1  riastrad 	switch (raw_edid[0]) {
   1161       1.1  riastrad 	case 0: /* base */
   1162       1.1  riastrad 		if (edid->version != 1) {
   1163       1.1  riastrad 			DRM_ERROR("EDID has major version %d, instead of 1\n", edid->version);
   1164       1.1  riastrad 			goto bad;
   1165       1.1  riastrad 		}
   1166       1.1  riastrad 
   1167       1.1  riastrad 		if (edid->revision > 4)
   1168       1.1  riastrad 			DRM_DEBUG("EDID minor > 4, assuming backward compatibility\n");
   1169       1.1  riastrad 		break;
   1170       1.1  riastrad 
   1171       1.1  riastrad 	default:
   1172       1.1  riastrad 		break;
   1173       1.1  riastrad 	}
   1174       1.1  riastrad 
   1175       1.3  riastrad 	return true;
   1176       1.1  riastrad 
   1177       1.1  riastrad bad:
   1178       1.3  riastrad 	if (print_bad_edid) {
   1179  1.5.16.1  pgoyette 		if (drm_edid_is_zero(raw_edid, EDID_LENGTH)) {
   1180  1.5.16.1  pgoyette 			printk(KERN_ERR "EDID block is all zeroes\n");
   1181  1.5.16.1  pgoyette 		} else {
   1182  1.5.16.1  pgoyette 			printk(KERN_ERR "Raw EDID:\n");
   1183  1.5.16.1  pgoyette 			print_hex_dump(KERN_ERR, " \t", DUMP_PREFIX_NONE, 16, 1,
   1184       1.1  riastrad 			       raw_edid, EDID_LENGTH, false);
   1185  1.5.16.1  pgoyette 		}
   1186       1.1  riastrad 	}
   1187       1.3  riastrad 	return false;
   1188       1.1  riastrad }
   1189       1.1  riastrad EXPORT_SYMBOL(drm_edid_block_valid);
   1190       1.1  riastrad 
   1191       1.1  riastrad /**
   1192       1.1  riastrad  * drm_edid_is_valid - sanity check EDID data
   1193       1.1  riastrad  * @edid: EDID data
   1194       1.1  riastrad  *
   1195       1.1  riastrad  * Sanity-check an entire EDID record (including extensions)
   1196  1.5.16.1  pgoyette  *
   1197  1.5.16.1  pgoyette  * Return: True if the EDID data is valid, false otherwise.
   1198       1.1  riastrad  */
   1199       1.1  riastrad bool drm_edid_is_valid(struct edid *edid)
   1200       1.1  riastrad {
   1201       1.1  riastrad 	int i;
   1202       1.1  riastrad 	u8 *raw = (u8 *)edid;
   1203       1.1  riastrad 
   1204       1.1  riastrad 	if (!edid)
   1205       1.1  riastrad 		return false;
   1206       1.1  riastrad 
   1207       1.1  riastrad 	for (i = 0; i <= edid->extensions; i++)
   1208  1.5.16.1  pgoyette 		if (!drm_edid_block_valid(raw + i * EDID_LENGTH, i, true, NULL))
   1209       1.1  riastrad 			return false;
   1210       1.1  riastrad 
   1211       1.1  riastrad 	return true;
   1212       1.1  riastrad }
   1213       1.1  riastrad EXPORT_SYMBOL(drm_edid_is_valid);
   1214       1.1  riastrad 
   1215       1.1  riastrad #define DDC_SEGMENT_ADDR 0x30
   1216       1.1  riastrad /**
   1217  1.5.16.1  pgoyette  * drm_do_probe_ddc_edid() - get EDID information via I2C
   1218  1.5.16.1  pgoyette  * @data: I2C device adapter
   1219       1.3  riastrad  * @buf: EDID data buffer to be filled
   1220       1.3  riastrad  * @block: 128 byte EDID block to start fetching from
   1221       1.3  riastrad  * @len: EDID data buffer length to fetch
   1222       1.3  riastrad  *
   1223  1.5.16.1  pgoyette  * Try to fetch EDID information by calling I2C driver functions.
   1224       1.1  riastrad  *
   1225  1.5.16.1  pgoyette  * Return: 0 on success or -1 on failure.
   1226       1.1  riastrad  */
   1227       1.1  riastrad static int
   1228  1.5.16.1  pgoyette drm_do_probe_ddc_edid(void *data, u8 *buf, unsigned int block, size_t len)
   1229       1.1  riastrad {
   1230  1.5.16.1  pgoyette 	struct i2c_adapter *adapter = data;
   1231       1.1  riastrad 	unsigned char start = block * EDID_LENGTH;
   1232       1.1  riastrad 	unsigned char segment = block >> 1;
   1233       1.1  riastrad 	unsigned char xfers = segment ? 3 : 2;
   1234       1.1  riastrad 	int ret, retries = 5;
   1235       1.1  riastrad 
   1236  1.5.16.1  pgoyette 	/*
   1237  1.5.16.1  pgoyette 	 * The core I2C driver will automatically retry the transfer if the
   1238       1.1  riastrad 	 * adapter reports EAGAIN. However, we find that bit-banging transfers
   1239       1.1  riastrad 	 * are susceptible to errors under a heavily loaded machine and
   1240       1.1  riastrad 	 * generate spurious NAKs and timeouts. Retrying the transfer
   1241       1.1  riastrad 	 * of the individual block a few times seems to overcome this.
   1242       1.1  riastrad 	 */
   1243       1.1  riastrad 	do {
   1244       1.1  riastrad 		struct i2c_msg msgs[] = {
   1245       1.1  riastrad 			{
   1246       1.1  riastrad 				.addr	= DDC_SEGMENT_ADDR,
   1247       1.1  riastrad 				.flags	= 0,
   1248       1.1  riastrad 				.len	= 1,
   1249       1.1  riastrad 				.buf	= &segment,
   1250       1.1  riastrad 			}, {
   1251       1.1  riastrad 				.addr	= DDC_ADDR,
   1252       1.1  riastrad 				.flags	= 0,
   1253       1.1  riastrad 				.len	= 1,
   1254       1.1  riastrad 				.buf	= &start,
   1255       1.1  riastrad 			}, {
   1256       1.1  riastrad 				.addr	= DDC_ADDR,
   1257       1.1  riastrad 				.flags	= I2C_M_RD,
   1258       1.1  riastrad 				.len	= len,
   1259       1.1  riastrad 				.buf	= buf,
   1260       1.1  riastrad 			}
   1261       1.1  riastrad 		};
   1262       1.1  riastrad 
   1263  1.5.16.1  pgoyette 		/*
   1264  1.5.16.1  pgoyette 		 * Avoid sending the segment addr to not upset non-compliant
   1265  1.5.16.1  pgoyette 		 * DDC monitors.
   1266  1.5.16.1  pgoyette 		 */
   1267       1.1  riastrad 		ret = i2c_transfer(adapter, &msgs[3 - xfers], xfers);
   1268       1.1  riastrad 
   1269       1.1  riastrad 		if (ret == -ENXIO) {
   1270       1.1  riastrad 			DRM_DEBUG_KMS("drm: skipping non-existent adapter %s\n",
   1271       1.1  riastrad 					adapter->name);
   1272       1.1  riastrad 			break;
   1273       1.1  riastrad 		}
   1274       1.1  riastrad 	} while (ret != xfers && --retries);
   1275       1.1  riastrad 
   1276       1.1  riastrad 	return ret == xfers ? 0 : -1;
   1277       1.1  riastrad }
   1278       1.1  riastrad 
   1279  1.5.16.1  pgoyette /**
   1280  1.5.16.1  pgoyette  * drm_do_get_edid - get EDID data using a custom EDID block read function
   1281  1.5.16.1  pgoyette  * @connector: connector we're probing
   1282  1.5.16.1  pgoyette  * @get_edid_block: EDID block read function
   1283  1.5.16.1  pgoyette  * @data: private data passed to the block read function
   1284  1.5.16.1  pgoyette  *
   1285  1.5.16.1  pgoyette  * When the I2C adapter connected to the DDC bus is hidden behind a device that
   1286  1.5.16.1  pgoyette  * exposes a different interface to read EDID blocks this function can be used
   1287  1.5.16.1  pgoyette  * to get EDID data using a custom block read function.
   1288  1.5.16.1  pgoyette  *
   1289  1.5.16.1  pgoyette  * As in the general case the DDC bus is accessible by the kernel at the I2C
   1290  1.5.16.1  pgoyette  * level, drivers must make all reasonable efforts to expose it as an I2C
   1291  1.5.16.1  pgoyette  * adapter and use drm_get_edid() instead of abusing this function.
   1292  1.5.16.1  pgoyette  *
   1293  1.5.16.1  pgoyette  * Return: Pointer to valid EDID or NULL if we couldn't find any.
   1294  1.5.16.1  pgoyette  */
   1295  1.5.16.1  pgoyette struct edid *drm_do_get_edid(struct drm_connector *connector,
   1296  1.5.16.1  pgoyette 	int (*get_edid_block)(void *data, u8 *buf, unsigned int block,
   1297  1.5.16.1  pgoyette 			      size_t len),
   1298  1.5.16.1  pgoyette 	void *data)
   1299       1.1  riastrad {
   1300       1.1  riastrad 	int i, j = 0, valid_extensions = 0;
   1301       1.1  riastrad 	u8 *block, *new;
   1302       1.1  riastrad 	bool print_bad_edid = !connector->bad_edid_counter || (drm_debug & DRM_UT_KMS);
   1303       1.1  riastrad 
   1304       1.1  riastrad 	if ((block = kmalloc(EDID_LENGTH, GFP_KERNEL)) == NULL)
   1305       1.1  riastrad 		return NULL;
   1306       1.1  riastrad 
   1307       1.1  riastrad 	/* base block fetch */
   1308       1.1  riastrad 	for (i = 0; i < 4; i++) {
   1309  1.5.16.1  pgoyette 		if (get_edid_block(data, block, 0, EDID_LENGTH))
   1310       1.1  riastrad 			goto out;
   1311  1.5.16.1  pgoyette 		if (drm_edid_block_valid(block, 0, print_bad_edid,
   1312  1.5.16.1  pgoyette 					 &connector->edid_corrupt))
   1313       1.1  riastrad 			break;
   1314       1.1  riastrad 		if (i == 0 && drm_edid_is_zero(block, EDID_LENGTH)) {
   1315       1.1  riastrad 			connector->null_edid_counter++;
   1316       1.1  riastrad 			goto carp;
   1317       1.1  riastrad 		}
   1318       1.1  riastrad 	}
   1319       1.1  riastrad 	if (i == 4)
   1320       1.1  riastrad 		goto carp;
   1321       1.1  riastrad 
   1322       1.1  riastrad 	/* if there's no extensions, we're done */
   1323       1.1  riastrad 	if (block[0x7e] == 0)
   1324  1.5.16.1  pgoyette 		return (struct edid *)block;
   1325       1.1  riastrad 
   1326       1.1  riastrad 	new = krealloc(block, (block[0x7e] + 1) * EDID_LENGTH, GFP_KERNEL);
   1327       1.1  riastrad 	if (!new)
   1328       1.1  riastrad 		goto out;
   1329       1.1  riastrad 	block = new;
   1330       1.1  riastrad 
   1331       1.1  riastrad 	for (j = 1; j <= block[0x7e]; j++) {
   1332       1.1  riastrad 		for (i = 0; i < 4; i++) {
   1333  1.5.16.1  pgoyette 			if (get_edid_block(data,
   1334       1.1  riastrad 				  block + (valid_extensions + 1) * EDID_LENGTH,
   1335       1.1  riastrad 				  j, EDID_LENGTH))
   1336       1.1  riastrad 				goto out;
   1337  1.5.16.1  pgoyette 			if (drm_edid_block_valid(block + (valid_extensions + 1)
   1338  1.5.16.1  pgoyette 						 * EDID_LENGTH, j,
   1339  1.5.16.1  pgoyette 						 print_bad_edid,
   1340  1.5.16.1  pgoyette 						 NULL)) {
   1341       1.1  riastrad 				valid_extensions++;
   1342       1.1  riastrad 				break;
   1343       1.1  riastrad 			}
   1344       1.1  riastrad 		}
   1345       1.3  riastrad 
   1346       1.3  riastrad 		if (i == 4 && print_bad_edid) {
   1347       1.1  riastrad 			dev_warn(connector->dev->dev,
   1348       1.1  riastrad 			 "%s: Ignoring invalid EDID block %d.\n",
   1349  1.5.16.1  pgoyette 			 connector->name, j);
   1350       1.3  riastrad 
   1351       1.3  riastrad 			connector->bad_edid_counter++;
   1352       1.3  riastrad 		}
   1353       1.1  riastrad 	}
   1354       1.1  riastrad 
   1355       1.1  riastrad 	if (valid_extensions != block[0x7e]) {
   1356       1.1  riastrad 		block[EDID_LENGTH-1] += block[0x7e] - valid_extensions;
   1357       1.1  riastrad 		block[0x7e] = valid_extensions;
   1358       1.1  riastrad 		new = krealloc(block, (valid_extensions + 1) * EDID_LENGTH, GFP_KERNEL);
   1359       1.1  riastrad 		if (!new)
   1360       1.1  riastrad 			goto out;
   1361       1.1  riastrad 		block = new;
   1362       1.1  riastrad 	}
   1363       1.1  riastrad 
   1364  1.5.16.1  pgoyette 	return (struct edid *)block;
   1365       1.1  riastrad 
   1366       1.1  riastrad carp:
   1367       1.1  riastrad 	if (print_bad_edid) {
   1368       1.1  riastrad 		dev_warn(connector->dev->dev, "%s: EDID block %d invalid.\n",
   1369  1.5.16.1  pgoyette 			 connector->name, j);
   1370       1.1  riastrad 	}
   1371       1.1  riastrad 	connector->bad_edid_counter++;
   1372       1.1  riastrad 
   1373       1.1  riastrad out:
   1374       1.1  riastrad 	kfree(block);
   1375       1.1  riastrad 	return NULL;
   1376       1.1  riastrad }
   1377  1.5.16.1  pgoyette EXPORT_SYMBOL_GPL(drm_do_get_edid);
   1378       1.1  riastrad 
   1379       1.1  riastrad /**
   1380  1.5.16.1  pgoyette  * drm_probe_ddc() - probe DDC presence
   1381  1.5.16.1  pgoyette  * @adapter: I2C adapter to probe
   1382       1.3  riastrad  *
   1383  1.5.16.1  pgoyette  * Return: True on success, false on failure.
   1384       1.1  riastrad  */
   1385       1.1  riastrad bool
   1386       1.1  riastrad drm_probe_ddc(struct i2c_adapter *adapter)
   1387       1.1  riastrad {
   1388       1.1  riastrad 	unsigned char out;
   1389       1.1  riastrad 
   1390       1.1  riastrad 	return (drm_do_probe_ddc_edid(adapter, &out, 0, 1) == 0);
   1391       1.1  riastrad }
   1392       1.1  riastrad EXPORT_SYMBOL(drm_probe_ddc);
   1393       1.1  riastrad 
   1394       1.1  riastrad /**
   1395       1.1  riastrad  * drm_get_edid - get EDID data, if available
   1396       1.1  riastrad  * @connector: connector we're probing
   1397  1.5.16.1  pgoyette  * @adapter: I2C adapter to use for DDC
   1398       1.1  riastrad  *
   1399  1.5.16.1  pgoyette  * Poke the given I2C channel to grab EDID data if possible.  If found,
   1400       1.1  riastrad  * attach it to the connector.
   1401       1.1  riastrad  *
   1402  1.5.16.1  pgoyette  * Return: Pointer to valid EDID or NULL if we couldn't find any.
   1403       1.1  riastrad  */
   1404       1.1  riastrad struct edid *drm_get_edid(struct drm_connector *connector,
   1405       1.1  riastrad 			  struct i2c_adapter *adapter)
   1406       1.1  riastrad {
   1407  1.5.16.1  pgoyette 	struct edid *edid;
   1408       1.1  riastrad 
   1409  1.5.16.1  pgoyette 	if (!drm_probe_ddc(adapter))
   1410  1.5.16.1  pgoyette 		return NULL;
   1411       1.1  riastrad 
   1412  1.5.16.1  pgoyette 	edid = drm_do_get_edid(connector, drm_do_probe_ddc_edid, adapter);
   1413  1.5.16.1  pgoyette 	if (edid)
   1414  1.5.16.1  pgoyette 		drm_get_displayid(connector, edid);
   1415       1.1  riastrad 	return edid;
   1416       1.1  riastrad }
   1417       1.1  riastrad EXPORT_SYMBOL(drm_get_edid);
   1418       1.1  riastrad 
   1419       1.3  riastrad /**
   1420       1.3  riastrad  * drm_edid_duplicate - duplicate an EDID and the extensions
   1421       1.3  riastrad  * @edid: EDID to duplicate
   1422       1.3  riastrad  *
   1423  1.5.16.1  pgoyette  * Return: Pointer to duplicated EDID or NULL on allocation failure.
   1424       1.3  riastrad  */
   1425       1.3  riastrad struct edid *drm_edid_duplicate(const struct edid *edid)
   1426       1.3  riastrad {
   1427       1.3  riastrad 	return kmemdup(edid, (edid->extensions + 1) * EDID_LENGTH, GFP_KERNEL);
   1428       1.3  riastrad }
   1429       1.3  riastrad EXPORT_SYMBOL(drm_edid_duplicate);
   1430       1.3  riastrad 
   1431       1.1  riastrad /*** EDID parsing ***/
   1432       1.1  riastrad 
   1433       1.1  riastrad /**
   1434       1.1  riastrad  * edid_vendor - match a string against EDID's obfuscated vendor field
   1435       1.1  riastrad  * @edid: EDID to match
   1436       1.1  riastrad  * @vendor: vendor string
   1437       1.1  riastrad  *
   1438       1.1  riastrad  * Returns true if @vendor is in @edid, false otherwise
   1439       1.1  riastrad  */
   1440       1.1  riastrad static bool edid_vendor(struct edid *edid, char *vendor)
   1441       1.1  riastrad {
   1442       1.1  riastrad 	char edid_vendor[3];
   1443       1.1  riastrad 
   1444       1.1  riastrad 	edid_vendor[0] = ((edid->mfg_id[0] & 0x7c) >> 2) + '@';
   1445       1.1  riastrad 	edid_vendor[1] = (((edid->mfg_id[0] & 0x3) << 3) |
   1446       1.1  riastrad 			  ((edid->mfg_id[1] & 0xe0) >> 5)) + '@';
   1447       1.1  riastrad 	edid_vendor[2] = (edid->mfg_id[1] & 0x1f) + '@';
   1448       1.1  riastrad 
   1449       1.1  riastrad 	return !strncmp(edid_vendor, vendor, 3);
   1450       1.1  riastrad }
   1451       1.1  riastrad 
   1452       1.1  riastrad /**
   1453       1.1  riastrad  * edid_get_quirks - return quirk flags for a given EDID
   1454       1.1  riastrad  * @edid: EDID to process
   1455       1.1  riastrad  *
   1456       1.1  riastrad  * This tells subsequent routines what fixes they need to apply.
   1457       1.1  riastrad  */
   1458       1.1  riastrad static u32 edid_get_quirks(struct edid *edid)
   1459       1.1  riastrad {
   1460       1.1  riastrad 	struct edid_quirk *quirk;
   1461       1.1  riastrad 	int i;
   1462       1.1  riastrad 
   1463       1.1  riastrad 	for (i = 0; i < ARRAY_SIZE(edid_quirk_list); i++) {
   1464       1.1  riastrad 		quirk = &edid_quirk_list[i];
   1465       1.1  riastrad 
   1466       1.1  riastrad 		if (edid_vendor(edid, quirk->vendor) &&
   1467       1.1  riastrad 		    (EDID_PRODUCT_ID(edid) == quirk->product_id))
   1468       1.1  riastrad 			return quirk->quirks;
   1469       1.1  riastrad 	}
   1470       1.1  riastrad 
   1471       1.1  riastrad 	return 0;
   1472       1.1  riastrad }
   1473       1.1  riastrad 
   1474       1.1  riastrad #define MODE_SIZE(m) ((m)->hdisplay * (m)->vdisplay)
   1475       1.3  riastrad #define MODE_REFRESH_DIFF(c,t) (abs((c) - (t)))
   1476       1.1  riastrad 
   1477       1.1  riastrad /**
   1478       1.1  riastrad  * edid_fixup_preferred - set preferred modes based on quirk list
   1479       1.1  riastrad  * @connector: has mode list to fix up
   1480       1.1  riastrad  * @quirks: quirks list
   1481       1.1  riastrad  *
   1482       1.1  riastrad  * Walk the mode list for @connector, clearing the preferred status
   1483       1.1  riastrad  * on existing modes and setting it anew for the right mode ala @quirks.
   1484       1.1  riastrad  */
   1485       1.1  riastrad static void edid_fixup_preferred(struct drm_connector *connector,
   1486       1.1  riastrad 				 u32 quirks)
   1487       1.1  riastrad {
   1488       1.1  riastrad 	struct drm_display_mode *t, *cur_mode, *preferred_mode;
   1489       1.1  riastrad 	int target_refresh = 0;
   1490       1.3  riastrad 	int cur_vrefresh, preferred_vrefresh;
   1491       1.1  riastrad 
   1492       1.1  riastrad 	if (list_empty(&connector->probed_modes))
   1493       1.1  riastrad 		return;
   1494       1.1  riastrad 
   1495       1.1  riastrad 	if (quirks & EDID_QUIRK_PREFER_LARGE_60)
   1496       1.1  riastrad 		target_refresh = 60;
   1497       1.1  riastrad 	if (quirks & EDID_QUIRK_PREFER_LARGE_75)
   1498       1.1  riastrad 		target_refresh = 75;
   1499       1.1  riastrad 
   1500       1.1  riastrad 	preferred_mode = list_first_entry(&connector->probed_modes,
   1501       1.1  riastrad 					  struct drm_display_mode, head);
   1502       1.1  riastrad 
   1503       1.1  riastrad 	list_for_each_entry_safe(cur_mode, t, &connector->probed_modes, head) {
   1504       1.1  riastrad 		cur_mode->type &= ~DRM_MODE_TYPE_PREFERRED;
   1505       1.1  riastrad 
   1506       1.1  riastrad 		if (cur_mode == preferred_mode)
   1507       1.1  riastrad 			continue;
   1508       1.1  riastrad 
   1509       1.1  riastrad 		/* Largest mode is preferred */
   1510       1.1  riastrad 		if (MODE_SIZE(cur_mode) > MODE_SIZE(preferred_mode))
   1511       1.1  riastrad 			preferred_mode = cur_mode;
   1512       1.1  riastrad 
   1513       1.3  riastrad 		cur_vrefresh = cur_mode->vrefresh ?
   1514       1.3  riastrad 			cur_mode->vrefresh : drm_mode_vrefresh(cur_mode);
   1515       1.3  riastrad 		preferred_vrefresh = preferred_mode->vrefresh ?
   1516       1.3  riastrad 			preferred_mode->vrefresh : drm_mode_vrefresh(preferred_mode);
   1517       1.1  riastrad 		/* At a given size, try to get closest to target refresh */
   1518       1.1  riastrad 		if ((MODE_SIZE(cur_mode) == MODE_SIZE(preferred_mode)) &&
   1519       1.3  riastrad 		    MODE_REFRESH_DIFF(cur_vrefresh, target_refresh) <
   1520       1.3  riastrad 		    MODE_REFRESH_DIFF(preferred_vrefresh, target_refresh)) {
   1521       1.1  riastrad 			preferred_mode = cur_mode;
   1522       1.1  riastrad 		}
   1523       1.1  riastrad 	}
   1524       1.1  riastrad 
   1525       1.1  riastrad 	preferred_mode->type |= DRM_MODE_TYPE_PREFERRED;
   1526       1.1  riastrad }
   1527       1.1  riastrad 
   1528       1.1  riastrad static bool
   1529       1.1  riastrad mode_is_rb(const struct drm_display_mode *mode)
   1530       1.1  riastrad {
   1531       1.1  riastrad 	return (mode->htotal - mode->hdisplay == 160) &&
   1532       1.1  riastrad 	       (mode->hsync_end - mode->hdisplay == 80) &&
   1533       1.1  riastrad 	       (mode->hsync_end - mode->hsync_start == 32) &&
   1534       1.1  riastrad 	       (mode->vsync_start - mode->vdisplay == 3);
   1535       1.1  riastrad }
   1536       1.1  riastrad 
   1537       1.1  riastrad /*
   1538       1.1  riastrad  * drm_mode_find_dmt - Create a copy of a mode if present in DMT
   1539       1.1  riastrad  * @dev: Device to duplicate against
   1540       1.1  riastrad  * @hsize: Mode width
   1541       1.1  riastrad  * @vsize: Mode height
   1542       1.1  riastrad  * @fresh: Mode refresh rate
   1543       1.1  riastrad  * @rb: Mode reduced-blanking-ness
   1544       1.1  riastrad  *
   1545       1.1  riastrad  * Walk the DMT mode list looking for a match for the given parameters.
   1546  1.5.16.1  pgoyette  *
   1547  1.5.16.1  pgoyette  * Return: A newly allocated copy of the mode, or NULL if not found.
   1548       1.1  riastrad  */
   1549       1.1  riastrad struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
   1550       1.1  riastrad 					   int hsize, int vsize, int fresh,
   1551       1.1  riastrad 					   bool rb)
   1552       1.1  riastrad {
   1553       1.1  riastrad 	int i;
   1554       1.1  riastrad 
   1555       1.3  riastrad 	for (i = 0; i < ARRAY_SIZE(drm_dmt_modes); i++) {
   1556       1.1  riastrad 		const struct drm_display_mode *ptr = &drm_dmt_modes[i];
   1557       1.1  riastrad 		if (hsize != ptr->hdisplay)
   1558       1.1  riastrad 			continue;
   1559       1.1  riastrad 		if (vsize != ptr->vdisplay)
   1560       1.1  riastrad 			continue;
   1561       1.1  riastrad 		if (fresh != drm_mode_vrefresh(ptr))
   1562       1.1  riastrad 			continue;
   1563       1.1  riastrad 		if (rb != mode_is_rb(ptr))
   1564       1.1  riastrad 			continue;
   1565       1.1  riastrad 
   1566       1.1  riastrad 		return drm_mode_duplicate(dev, ptr);
   1567       1.1  riastrad 	}
   1568       1.1  riastrad 
   1569       1.1  riastrad 	return NULL;
   1570       1.1  riastrad }
   1571       1.1  riastrad EXPORT_SYMBOL(drm_mode_find_dmt);
   1572       1.1  riastrad 
   1573       1.1  riastrad typedef void detailed_cb(struct detailed_timing *timing, void *closure);
   1574       1.1  riastrad 
   1575       1.1  riastrad static void
   1576       1.1  riastrad cea_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
   1577       1.1  riastrad {
   1578       1.1  riastrad 	int i, n = 0;
   1579       1.1  riastrad 	u8 d = ext[0x02];
   1580       1.1  riastrad 	u8 *det_base = ext + d;
   1581       1.1  riastrad 
   1582       1.1  riastrad 	n = (127 - d) / 18;
   1583       1.1  riastrad 	for (i = 0; i < n; i++)
   1584       1.1  riastrad 		cb((struct detailed_timing *)(det_base + 18 * i), closure);
   1585       1.1  riastrad }
   1586       1.1  riastrad 
   1587       1.1  riastrad static void
   1588       1.1  riastrad vtb_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
   1589       1.1  riastrad {
   1590       1.1  riastrad 	unsigned int i, n = min((int)ext[0x02], 6);
   1591       1.1  riastrad 	u8 *det_base = ext + 5;
   1592       1.1  riastrad 
   1593       1.1  riastrad 	if (ext[0x01] != 1)
   1594       1.1  riastrad 		return; /* unknown version */
   1595       1.1  riastrad 
   1596       1.1  riastrad 	for (i = 0; i < n; i++)
   1597       1.1  riastrad 		cb((struct detailed_timing *)(det_base + 18 * i), closure);
   1598       1.1  riastrad }
   1599       1.1  riastrad 
   1600       1.1  riastrad static void
   1601       1.1  riastrad drm_for_each_detailed_block(u8 *raw_edid, detailed_cb *cb, void *closure)
   1602       1.1  riastrad {
   1603       1.1  riastrad 	int i;
   1604       1.1  riastrad 	struct edid *edid = (struct edid *)raw_edid;
   1605       1.1  riastrad 
   1606       1.1  riastrad 	if (edid == NULL)
   1607       1.1  riastrad 		return;
   1608       1.1  riastrad 
   1609       1.1  riastrad 	for (i = 0; i < EDID_DETAILED_TIMINGS; i++)
   1610       1.1  riastrad 		cb(&(edid->detailed_timings[i]), closure);
   1611       1.1  riastrad 
   1612       1.1  riastrad 	for (i = 1; i <= raw_edid[0x7e]; i++) {
   1613       1.1  riastrad 		u8 *ext = raw_edid + (i * EDID_LENGTH);
   1614       1.1  riastrad 		switch (*ext) {
   1615       1.1  riastrad 		case CEA_EXT:
   1616       1.1  riastrad 			cea_for_each_detailed_block(ext, cb, closure);
   1617       1.1  riastrad 			break;
   1618       1.1  riastrad 		case VTB_EXT:
   1619       1.1  riastrad 			vtb_for_each_detailed_block(ext, cb, closure);
   1620       1.1  riastrad 			break;
   1621       1.1  riastrad 		default:
   1622       1.1  riastrad 			break;
   1623       1.1  riastrad 		}
   1624       1.1  riastrad 	}
   1625       1.1  riastrad }
   1626       1.1  riastrad 
   1627       1.1  riastrad static void
   1628       1.1  riastrad is_rb(struct detailed_timing *t, void *data)
   1629       1.1  riastrad {
   1630       1.1  riastrad 	u8 *r = (u8 *)t;
   1631       1.1  riastrad 	if (r[3] == EDID_DETAIL_MONITOR_RANGE)
   1632       1.1  riastrad 		if (r[15] & 0x10)
   1633       1.1  riastrad 			*(bool *)data = true;
   1634       1.1  riastrad }
   1635       1.1  riastrad 
   1636       1.1  riastrad /* EDID 1.4 defines this explicitly.  For EDID 1.3, we guess, badly. */
   1637       1.1  riastrad static bool
   1638       1.1  riastrad drm_monitor_supports_rb(struct edid *edid)
   1639       1.1  riastrad {
   1640       1.1  riastrad 	if (edid->revision >= 4) {
   1641       1.1  riastrad 		bool ret = false;
   1642       1.1  riastrad 		drm_for_each_detailed_block((u8 *)edid, is_rb, &ret);
   1643       1.1  riastrad 		return ret;
   1644       1.1  riastrad 	}
   1645       1.1  riastrad 
   1646       1.1  riastrad 	return ((edid->input & DRM_EDID_INPUT_DIGITAL) != 0);
   1647       1.1  riastrad }
   1648       1.1  riastrad 
   1649       1.1  riastrad static void
   1650       1.1  riastrad find_gtf2(struct detailed_timing *t, void *data)
   1651       1.1  riastrad {
   1652       1.1  riastrad 	u8 *r = (u8 *)t;
   1653       1.1  riastrad 	if (r[3] == EDID_DETAIL_MONITOR_RANGE && r[10] == 0x02)
   1654       1.1  riastrad 		*(u8 **)data = r;
   1655       1.1  riastrad }
   1656       1.1  riastrad 
   1657       1.1  riastrad /* Secondary GTF curve kicks in above some break frequency */
   1658       1.1  riastrad static int
   1659       1.1  riastrad drm_gtf2_hbreak(struct edid *edid)
   1660       1.1  riastrad {
   1661       1.1  riastrad 	u8 *r = NULL;
   1662       1.1  riastrad 	drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
   1663       1.1  riastrad 	return r ? (r[12] * 2) : 0;
   1664       1.1  riastrad }
   1665       1.1  riastrad 
   1666       1.1  riastrad static int
   1667       1.1  riastrad drm_gtf2_2c(struct edid *edid)
   1668       1.1  riastrad {
   1669       1.1  riastrad 	u8 *r = NULL;
   1670       1.1  riastrad 	drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
   1671       1.1  riastrad 	return r ? r[13] : 0;
   1672       1.1  riastrad }
   1673       1.1  riastrad 
   1674       1.1  riastrad static int
   1675       1.1  riastrad drm_gtf2_m(struct edid *edid)
   1676       1.1  riastrad {
   1677       1.1  riastrad 	u8 *r = NULL;
   1678       1.1  riastrad 	drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
   1679       1.1  riastrad 	return r ? (r[15] << 8) + r[14] : 0;
   1680       1.1  riastrad }
   1681       1.1  riastrad 
   1682       1.1  riastrad static int
   1683       1.1  riastrad drm_gtf2_k(struct edid *edid)
   1684       1.1  riastrad {
   1685       1.1  riastrad 	u8 *r = NULL;
   1686       1.1  riastrad 	drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
   1687       1.1  riastrad 	return r ? r[16] : 0;
   1688       1.1  riastrad }
   1689       1.1  riastrad 
   1690       1.1  riastrad static int
   1691       1.1  riastrad drm_gtf2_2j(struct edid *edid)
   1692       1.1  riastrad {
   1693       1.1  riastrad 	u8 *r = NULL;
   1694       1.1  riastrad 	drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
   1695       1.1  riastrad 	return r ? r[17] : 0;
   1696       1.1  riastrad }
   1697       1.1  riastrad 
   1698       1.1  riastrad /**
   1699       1.1  riastrad  * standard_timing_level - get std. timing level(CVT/GTF/DMT)
   1700       1.1  riastrad  * @edid: EDID block to scan
   1701       1.1  riastrad  */
   1702       1.1  riastrad static int standard_timing_level(struct edid *edid)
   1703       1.1  riastrad {
   1704       1.1  riastrad 	if (edid->revision >= 2) {
   1705       1.1  riastrad 		if (edid->revision >= 4 && (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF))
   1706       1.1  riastrad 			return LEVEL_CVT;
   1707       1.1  riastrad 		if (drm_gtf2_hbreak(edid))
   1708       1.1  riastrad 			return LEVEL_GTF2;
   1709       1.1  riastrad 		return LEVEL_GTF;
   1710       1.1  riastrad 	}
   1711       1.1  riastrad 	return LEVEL_DMT;
   1712       1.1  riastrad }
   1713       1.1  riastrad 
   1714       1.1  riastrad /*
   1715       1.1  riastrad  * 0 is reserved.  The spec says 0x01 fill for unused timings.  Some old
   1716       1.1  riastrad  * monitors fill with ascii space (0x20) instead.
   1717       1.1  riastrad  */
   1718       1.1  riastrad static int
   1719       1.1  riastrad bad_std_timing(u8 a, u8 b)
   1720       1.1  riastrad {
   1721       1.1  riastrad 	return (a == 0x00 && b == 0x00) ||
   1722       1.1  riastrad 	       (a == 0x01 && b == 0x01) ||
   1723       1.1  riastrad 	       (a == 0x20 && b == 0x20);
   1724       1.1  riastrad }
   1725       1.1  riastrad 
   1726       1.1  riastrad /**
   1727       1.1  riastrad  * drm_mode_std - convert standard mode info (width, height, refresh) into mode
   1728       1.3  riastrad  * @connector: connector of for the EDID block
   1729       1.3  riastrad  * @edid: EDID block to scan
   1730       1.1  riastrad  * @t: standard timing params
   1731       1.1  riastrad  *
   1732       1.1  riastrad  * Take the standard timing params (in this case width, aspect, and refresh)
   1733       1.1  riastrad  * and convert them into a real mode using CVT/GTF/DMT.
   1734       1.1  riastrad  */
   1735       1.1  riastrad static struct drm_display_mode *
   1736       1.1  riastrad drm_mode_std(struct drm_connector *connector, struct edid *edid,
   1737  1.5.16.1  pgoyette 	     struct std_timing *t)
   1738       1.1  riastrad {
   1739       1.1  riastrad 	struct drm_device *dev = connector->dev;
   1740       1.1  riastrad 	struct drm_display_mode *m, *mode = NULL;
   1741       1.1  riastrad 	int hsize, vsize;
   1742       1.1  riastrad 	int vrefresh_rate;
   1743       1.1  riastrad 	unsigned aspect_ratio = (t->vfreq_aspect & EDID_TIMING_ASPECT_MASK)
   1744       1.1  riastrad 		>> EDID_TIMING_ASPECT_SHIFT;
   1745       1.1  riastrad 	unsigned vfreq = (t->vfreq_aspect & EDID_TIMING_VFREQ_MASK)
   1746       1.1  riastrad 		>> EDID_TIMING_VFREQ_SHIFT;
   1747       1.1  riastrad 	int timing_level = standard_timing_level(edid);
   1748       1.1  riastrad 
   1749       1.1  riastrad 	if (bad_std_timing(t->hsize, t->vfreq_aspect))
   1750       1.1  riastrad 		return NULL;
   1751       1.1  riastrad 
   1752       1.1  riastrad 	/* According to the EDID spec, the hdisplay = hsize * 8 + 248 */
   1753       1.1  riastrad 	hsize = t->hsize * 8 + 248;
   1754       1.1  riastrad 	/* vrefresh_rate = vfreq + 60 */
   1755       1.1  riastrad 	vrefresh_rate = vfreq + 60;
   1756       1.1  riastrad 	/* the vdisplay is calculated based on the aspect ratio */
   1757       1.1  riastrad 	if (aspect_ratio == 0) {
   1758  1.5.16.1  pgoyette 		if (edid->revision < 3)
   1759       1.1  riastrad 			vsize = hsize;
   1760       1.1  riastrad 		else
   1761       1.1  riastrad 			vsize = (hsize * 10) / 16;
   1762       1.1  riastrad 	} else if (aspect_ratio == 1)
   1763       1.1  riastrad 		vsize = (hsize * 3) / 4;
   1764       1.1  riastrad 	else if (aspect_ratio == 2)
   1765       1.1  riastrad 		vsize = (hsize * 4) / 5;
   1766       1.1  riastrad 	else
   1767       1.1  riastrad 		vsize = (hsize * 9) / 16;
   1768       1.1  riastrad 
   1769       1.1  riastrad 	/* HDTV hack, part 1 */
   1770       1.1  riastrad 	if (vrefresh_rate == 60 &&
   1771       1.1  riastrad 	    ((hsize == 1360 && vsize == 765) ||
   1772       1.1  riastrad 	     (hsize == 1368 && vsize == 769))) {
   1773       1.1  riastrad 		hsize = 1366;
   1774       1.1  riastrad 		vsize = 768;
   1775       1.1  riastrad 	}
   1776       1.1  riastrad 
   1777       1.1  riastrad 	/*
   1778       1.1  riastrad 	 * If this connector already has a mode for this size and refresh
   1779       1.1  riastrad 	 * rate (because it came from detailed or CVT info), use that
   1780       1.1  riastrad 	 * instead.  This way we don't have to guess at interlace or
   1781       1.1  riastrad 	 * reduced blanking.
   1782       1.1  riastrad 	 */
   1783       1.1  riastrad 	list_for_each_entry(m, &connector->probed_modes, head)
   1784       1.1  riastrad 		if (m->hdisplay == hsize && m->vdisplay == vsize &&
   1785       1.1  riastrad 		    drm_mode_vrefresh(m) == vrefresh_rate)
   1786       1.1  riastrad 			return NULL;
   1787       1.1  riastrad 
   1788       1.1  riastrad 	/* HDTV hack, part 2 */
   1789       1.1  riastrad 	if (hsize == 1366 && vsize == 768 && vrefresh_rate == 60) {
   1790       1.1  riastrad 		mode = drm_cvt_mode(dev, 1366, 768, vrefresh_rate, 0, 0,
   1791       1.1  riastrad 				    false);
   1792       1.1  riastrad 		mode->hdisplay = 1366;
   1793       1.1  riastrad 		mode->hsync_start = mode->hsync_start - 1;
   1794       1.1  riastrad 		mode->hsync_end = mode->hsync_end - 1;
   1795       1.1  riastrad 		return mode;
   1796       1.1  riastrad 	}
   1797       1.1  riastrad 
   1798       1.1  riastrad 	/* check whether it can be found in default mode table */
   1799       1.1  riastrad 	if (drm_monitor_supports_rb(edid)) {
   1800       1.1  riastrad 		mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate,
   1801       1.1  riastrad 					 true);
   1802       1.1  riastrad 		if (mode)
   1803       1.1  riastrad 			return mode;
   1804       1.1  riastrad 	}
   1805       1.1  riastrad 	mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate, false);
   1806       1.1  riastrad 	if (mode)
   1807       1.1  riastrad 		return mode;
   1808       1.1  riastrad 
   1809       1.1  riastrad 	/* okay, generate it */
   1810       1.1  riastrad 	switch (timing_level) {
   1811       1.1  riastrad 	case LEVEL_DMT:
   1812       1.1  riastrad 		break;
   1813       1.1  riastrad 	case LEVEL_GTF:
   1814       1.1  riastrad 		mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
   1815       1.1  riastrad 		break;
   1816       1.1  riastrad 	case LEVEL_GTF2:
   1817       1.1  riastrad 		/*
   1818       1.1  riastrad 		 * This is potentially wrong if there's ever a monitor with
   1819       1.1  riastrad 		 * more than one ranges section, each claiming a different
   1820       1.1  riastrad 		 * secondary GTF curve.  Please don't do that.
   1821       1.1  riastrad 		 */
   1822       1.1  riastrad 		mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
   1823       1.1  riastrad 		if (!mode)
   1824       1.1  riastrad 			return NULL;
   1825       1.1  riastrad 		if (drm_mode_hsync(mode) > drm_gtf2_hbreak(edid)) {
   1826       1.1  riastrad 			drm_mode_destroy(dev, mode);
   1827       1.1  riastrad 			mode = drm_gtf_mode_complex(dev, hsize, vsize,
   1828       1.1  riastrad 						    vrefresh_rate, 0, 0,
   1829       1.1  riastrad 						    drm_gtf2_m(edid),
   1830       1.1  riastrad 						    drm_gtf2_2c(edid),
   1831       1.1  riastrad 						    drm_gtf2_k(edid),
   1832       1.1  riastrad 						    drm_gtf2_2j(edid));
   1833       1.1  riastrad 		}
   1834       1.1  riastrad 		break;
   1835       1.1  riastrad 	case LEVEL_CVT:
   1836       1.1  riastrad 		mode = drm_cvt_mode(dev, hsize, vsize, vrefresh_rate, 0, 0,
   1837       1.1  riastrad 				    false);
   1838       1.1  riastrad 		break;
   1839       1.1  riastrad 	}
   1840       1.1  riastrad 	return mode;
   1841       1.1  riastrad }
   1842       1.1  riastrad 
   1843       1.1  riastrad /*
   1844       1.1  riastrad  * EDID is delightfully ambiguous about how interlaced modes are to be
   1845       1.1  riastrad  * encoded.  Our internal representation is of frame height, but some
   1846       1.1  riastrad  * HDTV detailed timings are encoded as field height.
   1847       1.1  riastrad  *
   1848       1.1  riastrad  * The format list here is from CEA, in frame size.  Technically we
   1849       1.1  riastrad  * should be checking refresh rate too.  Whatever.
   1850       1.1  riastrad  */
   1851       1.1  riastrad static void
   1852       1.1  riastrad drm_mode_do_interlace_quirk(struct drm_display_mode *mode,
   1853       1.1  riastrad 			    struct detailed_pixel_timing *pt)
   1854       1.1  riastrad {
   1855       1.1  riastrad 	int i;
   1856       1.1  riastrad 	static const struct {
   1857       1.1  riastrad 		int w, h;
   1858       1.1  riastrad 	} cea_interlaced[] = {
   1859       1.1  riastrad 		{ 1920, 1080 },
   1860       1.1  riastrad 		{  720,  480 },
   1861       1.1  riastrad 		{ 1440,  480 },
   1862       1.1  riastrad 		{ 2880,  480 },
   1863       1.1  riastrad 		{  720,  576 },
   1864       1.1  riastrad 		{ 1440,  576 },
   1865       1.1  riastrad 		{ 2880,  576 },
   1866       1.1  riastrad 	};
   1867       1.1  riastrad 
   1868       1.1  riastrad 	if (!(pt->misc & DRM_EDID_PT_INTERLACED))
   1869       1.1  riastrad 		return;
   1870       1.1  riastrad 
   1871       1.1  riastrad 	for (i = 0; i < ARRAY_SIZE(cea_interlaced); i++) {
   1872       1.1  riastrad 		if ((mode->hdisplay == cea_interlaced[i].w) &&
   1873       1.1  riastrad 		    (mode->vdisplay == cea_interlaced[i].h / 2)) {
   1874       1.1  riastrad 			mode->vdisplay *= 2;
   1875       1.1  riastrad 			mode->vsync_start *= 2;
   1876       1.1  riastrad 			mode->vsync_end *= 2;
   1877       1.1  riastrad 			mode->vtotal *= 2;
   1878       1.1  riastrad 			mode->vtotal |= 1;
   1879       1.1  riastrad 		}
   1880       1.1  riastrad 	}
   1881       1.1  riastrad 
   1882       1.1  riastrad 	mode->flags |= DRM_MODE_FLAG_INTERLACE;
   1883       1.1  riastrad }
   1884       1.1  riastrad 
   1885       1.1  riastrad /**
   1886       1.1  riastrad  * drm_mode_detailed - create a new mode from an EDID detailed timing section
   1887       1.1  riastrad  * @dev: DRM device (needed to create new mode)
   1888       1.1  riastrad  * @edid: EDID block
   1889       1.1  riastrad  * @timing: EDID detailed timing info
   1890       1.1  riastrad  * @quirks: quirks to apply
   1891       1.1  riastrad  *
   1892       1.1  riastrad  * An EDID detailed timing block contains enough info for us to create and
   1893       1.1  riastrad  * return a new struct drm_display_mode.
   1894       1.1  riastrad  */
   1895       1.1  riastrad static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev,
   1896       1.1  riastrad 						  struct edid *edid,
   1897       1.1  riastrad 						  struct detailed_timing *timing,
   1898       1.1  riastrad 						  u32 quirks)
   1899       1.1  riastrad {
   1900       1.1  riastrad 	struct drm_display_mode *mode;
   1901       1.1  riastrad 	struct detailed_pixel_timing *pt = &timing->data.pixel_data;
   1902       1.1  riastrad 	unsigned hactive = (pt->hactive_hblank_hi & 0xf0) << 4 | pt->hactive_lo;
   1903       1.1  riastrad 	unsigned vactive = (pt->vactive_vblank_hi & 0xf0) << 4 | pt->vactive_lo;
   1904       1.1  riastrad 	unsigned hblank = (pt->hactive_hblank_hi & 0xf) << 8 | pt->hblank_lo;
   1905       1.1  riastrad 	unsigned vblank = (pt->vactive_vblank_hi & 0xf) << 8 | pt->vblank_lo;
   1906       1.1  riastrad 	unsigned hsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc0) << 2 | pt->hsync_offset_lo;
   1907       1.1  riastrad 	unsigned hsync_pulse_width = (pt->hsync_vsync_offset_pulse_width_hi & 0x30) << 4 | pt->hsync_pulse_width_lo;
   1908       1.3  riastrad 	unsigned vsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc) << 2 | pt->vsync_offset_pulse_width_lo >> 4;
   1909       1.1  riastrad 	unsigned vsync_pulse_width = (pt->hsync_vsync_offset_pulse_width_hi & 0x3) << 4 | (pt->vsync_offset_pulse_width_lo & 0xf);
   1910       1.1  riastrad 
   1911       1.1  riastrad 	/* ignore tiny modes */
   1912       1.1  riastrad 	if (hactive < 64 || vactive < 64)
   1913       1.1  riastrad 		return NULL;
   1914       1.1  riastrad 
   1915       1.1  riastrad 	if (pt->misc & DRM_EDID_PT_STEREO) {
   1916       1.3  riastrad 		DRM_DEBUG_KMS("stereo mode not supported\n");
   1917       1.1  riastrad 		return NULL;
   1918       1.1  riastrad 	}
   1919       1.1  riastrad 	if (!(pt->misc & DRM_EDID_PT_SEPARATE_SYNC)) {
   1920       1.3  riastrad 		DRM_DEBUG_KMS("composite sync not supported\n");
   1921       1.1  riastrad 	}
   1922       1.1  riastrad 
   1923       1.1  riastrad 	/* it is incorrect if hsync/vsync width is zero */
   1924       1.1  riastrad 	if (!hsync_pulse_width || !vsync_pulse_width) {
   1925       1.1  riastrad 		DRM_DEBUG_KMS("Incorrect Detailed timing. "
   1926       1.1  riastrad 				"Wrong Hsync/Vsync pulse width\n");
   1927       1.1  riastrad 		return NULL;
   1928       1.1  riastrad 	}
   1929       1.1  riastrad 
   1930       1.1  riastrad 	if (quirks & EDID_QUIRK_FORCE_REDUCED_BLANKING) {
   1931       1.1  riastrad 		mode = drm_cvt_mode(dev, hactive, vactive, 60, true, false, false);
   1932       1.1  riastrad 		if (!mode)
   1933       1.1  riastrad 			return NULL;
   1934       1.1  riastrad 
   1935       1.1  riastrad 		goto set_size;
   1936       1.1  riastrad 	}
   1937       1.1  riastrad 
   1938       1.1  riastrad 	mode = drm_mode_create(dev);
   1939       1.1  riastrad 	if (!mode)
   1940       1.1  riastrad 		return NULL;
   1941       1.1  riastrad 
   1942       1.1  riastrad 	if (quirks & EDID_QUIRK_135_CLOCK_TOO_HIGH)
   1943       1.1  riastrad 		timing->pixel_clock = cpu_to_le16(1088);
   1944       1.1  riastrad 
   1945       1.1  riastrad 	mode->clock = le16_to_cpu(timing->pixel_clock) * 10;
   1946       1.1  riastrad 
   1947       1.1  riastrad 	mode->hdisplay = hactive;
   1948       1.1  riastrad 	mode->hsync_start = mode->hdisplay + hsync_offset;
   1949       1.1  riastrad 	mode->hsync_end = mode->hsync_start + hsync_pulse_width;
   1950       1.1  riastrad 	mode->htotal = mode->hdisplay + hblank;
   1951       1.1  riastrad 
   1952       1.1  riastrad 	mode->vdisplay = vactive;
   1953       1.1  riastrad 	mode->vsync_start = mode->vdisplay + vsync_offset;
   1954       1.1  riastrad 	mode->vsync_end = mode->vsync_start + vsync_pulse_width;
   1955       1.1  riastrad 	mode->vtotal = mode->vdisplay + vblank;
   1956       1.1  riastrad 
   1957       1.1  riastrad 	/* Some EDIDs have bogus h/vtotal values */
   1958       1.1  riastrad 	if (mode->hsync_end > mode->htotal)
   1959       1.1  riastrad 		mode->htotal = mode->hsync_end + 1;
   1960       1.1  riastrad 	if (mode->vsync_end > mode->vtotal)
   1961       1.1  riastrad 		mode->vtotal = mode->vsync_end + 1;
   1962       1.1  riastrad 
   1963       1.1  riastrad 	drm_mode_do_interlace_quirk(mode, pt);
   1964       1.1  riastrad 
   1965       1.1  riastrad 	if (quirks & EDID_QUIRK_DETAILED_SYNC_PP) {
   1966       1.1  riastrad 		pt->misc |= DRM_EDID_PT_HSYNC_POSITIVE | DRM_EDID_PT_VSYNC_POSITIVE;
   1967       1.1  riastrad 	}
   1968       1.1  riastrad 
   1969       1.1  riastrad 	mode->flags |= (pt->misc & DRM_EDID_PT_HSYNC_POSITIVE) ?
   1970       1.1  riastrad 		DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC;
   1971       1.1  riastrad 	mode->flags |= (pt->misc & DRM_EDID_PT_VSYNC_POSITIVE) ?
   1972       1.1  riastrad 		DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
   1973       1.1  riastrad 
   1974       1.1  riastrad set_size:
   1975       1.1  riastrad 	mode->width_mm = pt->width_mm_lo | (pt->width_height_mm_hi & 0xf0) << 4;
   1976       1.1  riastrad 	mode->height_mm = pt->height_mm_lo | (pt->width_height_mm_hi & 0xf) << 8;
   1977       1.1  riastrad 
   1978       1.1  riastrad 	if (quirks & EDID_QUIRK_DETAILED_IN_CM) {
   1979       1.1  riastrad 		mode->width_mm *= 10;
   1980       1.1  riastrad 		mode->height_mm *= 10;
   1981       1.1  riastrad 	}
   1982       1.1  riastrad 
   1983       1.1  riastrad 	if (quirks & EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE) {
   1984       1.1  riastrad 		mode->width_mm = edid->width_cm * 10;
   1985       1.1  riastrad 		mode->height_mm = edid->height_cm * 10;
   1986       1.1  riastrad 	}
   1987       1.1  riastrad 
   1988       1.1  riastrad 	mode->type = DRM_MODE_TYPE_DRIVER;
   1989       1.3  riastrad 	mode->vrefresh = drm_mode_vrefresh(mode);
   1990       1.1  riastrad 	drm_mode_set_name(mode);
   1991       1.1  riastrad 
   1992       1.1  riastrad 	return mode;
   1993       1.1  riastrad }
   1994       1.1  riastrad 
   1995       1.1  riastrad static bool
   1996       1.1  riastrad mode_in_hsync_range(const struct drm_display_mode *mode,
   1997       1.1  riastrad 		    struct edid *edid, u8 *t)
   1998       1.1  riastrad {
   1999       1.1  riastrad 	int hsync, hmin, hmax;
   2000       1.1  riastrad 
   2001       1.1  riastrad 	hmin = t[7];
   2002       1.1  riastrad 	if (edid->revision >= 4)
   2003       1.1  riastrad 	    hmin += ((t[4] & 0x04) ? 255 : 0);
   2004       1.1  riastrad 	hmax = t[8];
   2005       1.1  riastrad 	if (edid->revision >= 4)
   2006       1.1  riastrad 	    hmax += ((t[4] & 0x08) ? 255 : 0);
   2007       1.1  riastrad 	hsync = drm_mode_hsync(mode);
   2008       1.1  riastrad 
   2009       1.1  riastrad 	return (hsync <= hmax && hsync >= hmin);
   2010       1.1  riastrad }
   2011       1.1  riastrad 
   2012       1.1  riastrad static bool
   2013       1.1  riastrad mode_in_vsync_range(const struct drm_display_mode *mode,
   2014       1.1  riastrad 		    struct edid *edid, u8 *t)
   2015       1.1  riastrad {
   2016       1.1  riastrad 	int vsync, vmin, vmax;
   2017       1.1  riastrad 
   2018       1.1  riastrad 	vmin = t[5];
   2019       1.1  riastrad 	if (edid->revision >= 4)
   2020       1.1  riastrad 	    vmin += ((t[4] & 0x01) ? 255 : 0);
   2021       1.1  riastrad 	vmax = t[6];
   2022       1.1  riastrad 	if (edid->revision >= 4)
   2023       1.1  riastrad 	    vmax += ((t[4] & 0x02) ? 255 : 0);
   2024       1.1  riastrad 	vsync = drm_mode_vrefresh(mode);
   2025       1.1  riastrad 
   2026       1.1  riastrad 	return (vsync <= vmax && vsync >= vmin);
   2027       1.1  riastrad }
   2028       1.1  riastrad 
   2029       1.1  riastrad static u32
   2030       1.1  riastrad range_pixel_clock(struct edid *edid, u8 *t)
   2031       1.1  riastrad {
   2032       1.1  riastrad 	/* unspecified */
   2033       1.1  riastrad 	if (t[9] == 0 || t[9] == 255)
   2034       1.1  riastrad 		return 0;
   2035       1.1  riastrad 
   2036       1.1  riastrad 	/* 1.4 with CVT support gives us real precision, yay */
   2037       1.1  riastrad 	if (edid->revision >= 4 && t[10] == 0x04)
   2038       1.1  riastrad 		return (t[9] * 10000) - ((t[12] >> 2) * 250);
   2039       1.1  riastrad 
   2040       1.1  riastrad 	/* 1.3 is pathetic, so fuzz up a bit */
   2041       1.1  riastrad 	return t[9] * 10000 + 5001;
   2042       1.1  riastrad }
   2043       1.1  riastrad 
   2044       1.1  riastrad static bool
   2045       1.1  riastrad mode_in_range(const struct drm_display_mode *mode, struct edid *edid,
   2046       1.1  riastrad 	      struct detailed_timing *timing)
   2047       1.1  riastrad {
   2048       1.1  riastrad 	u32 max_clock;
   2049       1.1  riastrad 	u8 *t = (u8 *)timing;
   2050       1.1  riastrad 
   2051       1.1  riastrad 	if (!mode_in_hsync_range(mode, edid, t))
   2052       1.1  riastrad 		return false;
   2053       1.1  riastrad 
   2054       1.1  riastrad 	if (!mode_in_vsync_range(mode, edid, t))
   2055       1.1  riastrad 		return false;
   2056       1.1  riastrad 
   2057       1.1  riastrad 	if ((max_clock = range_pixel_clock(edid, t)))
   2058       1.1  riastrad 		if (mode->clock > max_clock)
   2059       1.1  riastrad 			return false;
   2060       1.1  riastrad 
   2061       1.1  riastrad 	/* 1.4 max horizontal check */
   2062       1.1  riastrad 	if (edid->revision >= 4 && t[10] == 0x04)
   2063       1.1  riastrad 		if (t[13] && mode->hdisplay > 8 * (t[13] + (256 * (t[12]&0x3))))
   2064       1.1  riastrad 			return false;
   2065       1.1  riastrad 
   2066       1.1  riastrad 	if (mode_is_rb(mode) && !drm_monitor_supports_rb(edid))
   2067       1.1  riastrad 		return false;
   2068       1.1  riastrad 
   2069       1.1  riastrad 	return true;
   2070       1.1  riastrad }
   2071       1.1  riastrad 
   2072       1.1  riastrad static bool valid_inferred_mode(const struct drm_connector *connector,
   2073       1.1  riastrad 				const struct drm_display_mode *mode)
   2074       1.1  riastrad {
   2075  1.5.16.1  pgoyette 	const struct drm_display_mode *m;
   2076       1.1  riastrad 	bool ok = false;
   2077       1.1  riastrad 
   2078       1.1  riastrad 	list_for_each_entry(m, &connector->probed_modes, head) {
   2079       1.1  riastrad 		if (mode->hdisplay == m->hdisplay &&
   2080       1.1  riastrad 		    mode->vdisplay == m->vdisplay &&
   2081       1.1  riastrad 		    drm_mode_vrefresh(mode) == drm_mode_vrefresh(m))
   2082       1.1  riastrad 			return false; /* duplicated */
   2083       1.1  riastrad 		if (mode->hdisplay <= m->hdisplay &&
   2084       1.1  riastrad 		    mode->vdisplay <= m->vdisplay)
   2085       1.1  riastrad 			ok = true;
   2086       1.1  riastrad 	}
   2087       1.1  riastrad 	return ok;
   2088       1.1  riastrad }
   2089       1.1  riastrad 
   2090       1.1  riastrad static int
   2091       1.1  riastrad drm_dmt_modes_for_range(struct drm_connector *connector, struct edid *edid,
   2092       1.1  riastrad 			struct detailed_timing *timing)
   2093       1.1  riastrad {
   2094       1.1  riastrad 	int i, modes = 0;
   2095       1.1  riastrad 	struct drm_display_mode *newmode;
   2096       1.1  riastrad 	struct drm_device *dev = connector->dev;
   2097       1.1  riastrad 
   2098       1.3  riastrad 	for (i = 0; i < ARRAY_SIZE(drm_dmt_modes); i++) {
   2099       1.1  riastrad 		if (mode_in_range(drm_dmt_modes + i, edid, timing) &&
   2100       1.1  riastrad 		    valid_inferred_mode(connector, drm_dmt_modes + i)) {
   2101       1.1  riastrad 			newmode = drm_mode_duplicate(dev, &drm_dmt_modes[i]);
   2102       1.1  riastrad 			if (newmode) {
   2103       1.1  riastrad 				drm_mode_probed_add(connector, newmode);
   2104       1.1  riastrad 				modes++;
   2105       1.1  riastrad 			}
   2106       1.1  riastrad 		}
   2107       1.1  riastrad 	}
   2108       1.1  riastrad 
   2109       1.1  riastrad 	return modes;
   2110       1.1  riastrad }
   2111       1.1  riastrad 
   2112       1.1  riastrad /* fix up 1366x768 mode from 1368x768;
   2113       1.1  riastrad  * GFT/CVT can't express 1366 width which isn't dividable by 8
   2114       1.1  riastrad  */
   2115       1.1  riastrad static void fixup_mode_1366x768(struct drm_display_mode *mode)
   2116       1.1  riastrad {
   2117       1.1  riastrad 	if (mode->hdisplay == 1368 && mode->vdisplay == 768) {
   2118       1.1  riastrad 		mode->hdisplay = 1366;
   2119       1.1  riastrad 		mode->hsync_start--;
   2120       1.1  riastrad 		mode->hsync_end--;
   2121       1.1  riastrad 		drm_mode_set_name(mode);
   2122       1.1  riastrad 	}
   2123       1.1  riastrad }
   2124       1.1  riastrad 
   2125       1.1  riastrad static int
   2126       1.1  riastrad drm_gtf_modes_for_range(struct drm_connector *connector, struct edid *edid,
   2127       1.1  riastrad 			struct detailed_timing *timing)
   2128       1.1  riastrad {
   2129       1.1  riastrad 	int i, modes = 0;
   2130       1.1  riastrad 	struct drm_display_mode *newmode;
   2131       1.1  riastrad 	struct drm_device *dev = connector->dev;
   2132       1.1  riastrad 
   2133       1.3  riastrad 	for (i = 0; i < ARRAY_SIZE(extra_modes); i++) {
   2134       1.1  riastrad 		const struct minimode *m = &extra_modes[i];
   2135       1.1  riastrad 		newmode = drm_gtf_mode(dev, m->w, m->h, m->r, 0, 0);
   2136       1.1  riastrad 		if (!newmode)
   2137       1.1  riastrad 			return modes;
   2138       1.1  riastrad 
   2139       1.1  riastrad 		fixup_mode_1366x768(newmode);
   2140       1.1  riastrad 		if (!mode_in_range(newmode, edid, timing) ||
   2141       1.1  riastrad 		    !valid_inferred_mode(connector, newmode)) {
   2142       1.1  riastrad 			drm_mode_destroy(dev, newmode);
   2143       1.1  riastrad 			continue;
   2144       1.1  riastrad 		}
   2145       1.1  riastrad 
   2146       1.1  riastrad 		drm_mode_probed_add(connector, newmode);
   2147       1.1  riastrad 		modes++;
   2148       1.1  riastrad 	}
   2149       1.1  riastrad 
   2150       1.1  riastrad 	return modes;
   2151       1.1  riastrad }
   2152       1.1  riastrad 
   2153       1.1  riastrad static int
   2154       1.1  riastrad drm_cvt_modes_for_range(struct drm_connector *connector, struct edid *edid,
   2155       1.1  riastrad 			struct detailed_timing *timing)
   2156       1.1  riastrad {
   2157       1.1  riastrad 	int i, modes = 0;
   2158       1.1  riastrad 	struct drm_display_mode *newmode;
   2159       1.1  riastrad 	struct drm_device *dev = connector->dev;
   2160       1.1  riastrad 	bool rb = drm_monitor_supports_rb(edid);
   2161       1.1  riastrad 
   2162       1.3  riastrad 	for (i = 0; i < ARRAY_SIZE(extra_modes); i++) {
   2163       1.1  riastrad 		const struct minimode *m = &extra_modes[i];
   2164       1.1  riastrad 		newmode = drm_cvt_mode(dev, m->w, m->h, m->r, rb, 0, 0);
   2165       1.1  riastrad 		if (!newmode)
   2166       1.1  riastrad 			return modes;
   2167       1.1  riastrad 
   2168       1.1  riastrad 		fixup_mode_1366x768(newmode);
   2169       1.1  riastrad 		if (!mode_in_range(newmode, edid, timing) ||
   2170       1.1  riastrad 		    !valid_inferred_mode(connector, newmode)) {
   2171       1.1  riastrad 			drm_mode_destroy(dev, newmode);
   2172       1.1  riastrad 			continue;
   2173       1.1  riastrad 		}
   2174       1.1  riastrad 
   2175       1.1  riastrad 		drm_mode_probed_add(connector, newmode);
   2176       1.1  riastrad 		modes++;
   2177       1.1  riastrad 	}
   2178       1.1  riastrad 
   2179       1.1  riastrad 	return modes;
   2180       1.1  riastrad }
   2181       1.1  riastrad 
   2182       1.1  riastrad static void
   2183       1.1  riastrad do_inferred_modes(struct detailed_timing *timing, void *c)
   2184       1.1  riastrad {
   2185       1.1  riastrad 	struct detailed_mode_closure *closure = c;
   2186       1.1  riastrad 	struct detailed_non_pixel *data = &timing->data.other_data;
   2187       1.1  riastrad 	struct detailed_data_monitor_range *range = &data->data.range;
   2188       1.1  riastrad 
   2189       1.1  riastrad 	if (data->type != EDID_DETAIL_MONITOR_RANGE)
   2190       1.1  riastrad 		return;
   2191       1.1  riastrad 
   2192       1.1  riastrad 	closure->modes += drm_dmt_modes_for_range(closure->connector,
   2193       1.1  riastrad 						  closure->edid,
   2194       1.1  riastrad 						  timing);
   2195       1.1  riastrad 
   2196       1.1  riastrad 	if (!version_greater(closure->edid, 1, 1))
   2197       1.1  riastrad 		return; /* GTF not defined yet */
   2198       1.1  riastrad 
   2199       1.1  riastrad 	switch (range->flags) {
   2200       1.1  riastrad 	case 0x02: /* secondary gtf, XXX could do more */
   2201       1.1  riastrad 	case 0x00: /* default gtf */
   2202       1.1  riastrad 		closure->modes += drm_gtf_modes_for_range(closure->connector,
   2203       1.1  riastrad 							  closure->edid,
   2204       1.1  riastrad 							  timing);
   2205       1.1  riastrad 		break;
   2206       1.1  riastrad 	case 0x04: /* cvt, only in 1.4+ */
   2207       1.1  riastrad 		if (!version_greater(closure->edid, 1, 3))
   2208       1.1  riastrad 			break;
   2209       1.1  riastrad 
   2210       1.1  riastrad 		closure->modes += drm_cvt_modes_for_range(closure->connector,
   2211       1.1  riastrad 							  closure->edid,
   2212       1.1  riastrad 							  timing);
   2213       1.1  riastrad 		break;
   2214       1.1  riastrad 	case 0x01: /* just the ranges, no formula */
   2215       1.1  riastrad 	default:
   2216       1.1  riastrad 		break;
   2217       1.1  riastrad 	}
   2218       1.1  riastrad }
   2219       1.1  riastrad 
   2220       1.1  riastrad static int
   2221       1.1  riastrad add_inferred_modes(struct drm_connector *connector, struct edid *edid)
   2222       1.1  riastrad {
   2223       1.1  riastrad 	struct detailed_mode_closure closure = {
   2224  1.5.16.1  pgoyette 		.connector = connector,
   2225  1.5.16.1  pgoyette 		.edid = edid,
   2226       1.1  riastrad 	};
   2227       1.1  riastrad 
   2228       1.1  riastrad 	if (version_greater(edid, 1, 0))
   2229       1.1  riastrad 		drm_for_each_detailed_block((u8 *)edid, do_inferred_modes,
   2230       1.1  riastrad 					    &closure);
   2231       1.1  riastrad 
   2232       1.1  riastrad 	return closure.modes;
   2233       1.1  riastrad }
   2234       1.1  riastrad 
   2235       1.1  riastrad static int
   2236       1.1  riastrad drm_est3_modes(struct drm_connector *connector, struct detailed_timing *timing)
   2237       1.1  riastrad {
   2238       1.1  riastrad 	int i, j, m, modes = 0;
   2239       1.1  riastrad 	struct drm_display_mode *mode;
   2240       1.1  riastrad 	u8 *est = ((u8 *)timing) + 5;
   2241       1.1  riastrad 
   2242       1.1  riastrad 	for (i = 0; i < 6; i++) {
   2243       1.3  riastrad 		for (j = 7; j >= 0; j--) {
   2244       1.1  riastrad 			m = (i * 8) + (7 - j);
   2245       1.1  riastrad 			if (m >= ARRAY_SIZE(est3_modes))
   2246       1.1  riastrad 				break;
   2247       1.1  riastrad 			if (est[i] & (1 << j)) {
   2248       1.1  riastrad 				mode = drm_mode_find_dmt(connector->dev,
   2249       1.1  riastrad 							 est3_modes[m].w,
   2250       1.1  riastrad 							 est3_modes[m].h,
   2251       1.1  riastrad 							 est3_modes[m].r,
   2252       1.1  riastrad 							 est3_modes[m].rb);
   2253       1.1  riastrad 				if (mode) {
   2254       1.1  riastrad 					drm_mode_probed_add(connector, mode);
   2255       1.1  riastrad 					modes++;
   2256       1.1  riastrad 				}
   2257       1.1  riastrad 			}
   2258       1.1  riastrad 		}
   2259       1.1  riastrad 	}
   2260       1.1  riastrad 
   2261       1.1  riastrad 	return modes;
   2262       1.1  riastrad }
   2263       1.1  riastrad 
   2264       1.1  riastrad static void
   2265       1.1  riastrad do_established_modes(struct detailed_timing *timing, void *c)
   2266       1.1  riastrad {
   2267       1.1  riastrad 	struct detailed_mode_closure *closure = c;
   2268       1.1  riastrad 	struct detailed_non_pixel *data = &timing->data.other_data;
   2269       1.1  riastrad 
   2270       1.1  riastrad 	if (data->type == EDID_DETAIL_EST_TIMINGS)
   2271       1.1  riastrad 		closure->modes += drm_est3_modes(closure->connector, timing);
   2272       1.1  riastrad }
   2273       1.1  riastrad 
   2274       1.1  riastrad /**
   2275       1.1  riastrad  * add_established_modes - get est. modes from EDID and add them
   2276  1.5.16.1  pgoyette  * @connector: connector to add mode(s) to
   2277       1.1  riastrad  * @edid: EDID block to scan
   2278       1.1  riastrad  *
   2279       1.1  riastrad  * Each EDID block contains a bitmap of the supported "established modes" list
   2280       1.1  riastrad  * (defined above).  Tease them out and add them to the global modes list.
   2281       1.1  riastrad  */
   2282       1.1  riastrad static int
   2283       1.1  riastrad add_established_modes(struct drm_connector *connector, struct edid *edid)
   2284       1.1  riastrad {
   2285       1.1  riastrad 	struct drm_device *dev = connector->dev;
   2286       1.1  riastrad 	unsigned long est_bits = edid->established_timings.t1 |
   2287       1.1  riastrad 		(edid->established_timings.t2 << 8) |
   2288       1.1  riastrad 		((edid->established_timings.mfg_rsvd & 0x80) << 9);
   2289       1.1  riastrad 	int i, modes = 0;
   2290       1.1  riastrad 	struct detailed_mode_closure closure = {
   2291  1.5.16.1  pgoyette 		.connector = connector,
   2292  1.5.16.1  pgoyette 		.edid = edid,
   2293       1.1  riastrad 	};
   2294       1.1  riastrad 
   2295       1.1  riastrad 	for (i = 0; i <= EDID_EST_TIMINGS; i++) {
   2296       1.1  riastrad 		if (est_bits & (1<<i)) {
   2297       1.1  riastrad 			struct drm_display_mode *newmode;
   2298       1.1  riastrad 			newmode = drm_mode_duplicate(dev, &edid_est_modes[i]);
   2299       1.1  riastrad 			if (newmode) {
   2300       1.1  riastrad 				drm_mode_probed_add(connector, newmode);
   2301       1.1  riastrad 				modes++;
   2302       1.1  riastrad 			}
   2303       1.1  riastrad 		}
   2304       1.1  riastrad 	}
   2305       1.1  riastrad 
   2306       1.1  riastrad 	if (version_greater(edid, 1, 0))
   2307       1.1  riastrad 		    drm_for_each_detailed_block((u8 *)edid,
   2308       1.1  riastrad 						do_established_modes, &closure);
   2309       1.1  riastrad 
   2310       1.1  riastrad 	return modes + closure.modes;
   2311       1.1  riastrad }
   2312       1.1  riastrad 
   2313       1.1  riastrad static void
   2314       1.1  riastrad do_standard_modes(struct detailed_timing *timing, void *c)
   2315       1.1  riastrad {
   2316       1.1  riastrad 	struct detailed_mode_closure *closure = c;
   2317       1.1  riastrad 	struct detailed_non_pixel *data = &timing->data.other_data;
   2318       1.1  riastrad 	struct drm_connector *connector = closure->connector;
   2319       1.1  riastrad 	struct edid *edid = closure->edid;
   2320       1.1  riastrad 
   2321       1.1  riastrad 	if (data->type == EDID_DETAIL_STD_MODES) {
   2322       1.1  riastrad 		int i;
   2323       1.1  riastrad 		for (i = 0; i < 6; i++) {
   2324       1.1  riastrad 			struct std_timing *std;
   2325       1.1  riastrad 			struct drm_display_mode *newmode;
   2326       1.1  riastrad 
   2327       1.1  riastrad 			std = &data->data.timings[i];
   2328  1.5.16.1  pgoyette 			newmode = drm_mode_std(connector, edid, std);
   2329       1.1  riastrad 			if (newmode) {
   2330       1.1  riastrad 				drm_mode_probed_add(connector, newmode);
   2331       1.1  riastrad 				closure->modes++;
   2332       1.1  riastrad 			}
   2333       1.1  riastrad 		}
   2334       1.1  riastrad 	}
   2335       1.1  riastrad }
   2336       1.1  riastrad 
   2337       1.1  riastrad /**
   2338       1.1  riastrad  * add_standard_modes - get std. modes from EDID and add them
   2339  1.5.16.1  pgoyette  * @connector: connector to add mode(s) to
   2340       1.1  riastrad  * @edid: EDID block to scan
   2341       1.1  riastrad  *
   2342       1.1  riastrad  * Standard modes can be calculated using the appropriate standard (DMT,
   2343       1.1  riastrad  * GTF or CVT. Grab them from @edid and add them to the list.
   2344       1.1  riastrad  */
   2345       1.1  riastrad static int
   2346       1.1  riastrad add_standard_modes(struct drm_connector *connector, struct edid *edid)
   2347       1.1  riastrad {
   2348       1.1  riastrad 	int i, modes = 0;
   2349       1.1  riastrad 	struct detailed_mode_closure closure = {
   2350  1.5.16.1  pgoyette 		.connector = connector,
   2351  1.5.16.1  pgoyette 		.edid = edid,
   2352       1.1  riastrad 	};
   2353       1.1  riastrad 
   2354       1.1  riastrad 	for (i = 0; i < EDID_STD_TIMINGS; i++) {
   2355       1.1  riastrad 		struct drm_display_mode *newmode;
   2356       1.1  riastrad 
   2357       1.1  riastrad 		newmode = drm_mode_std(connector, edid,
   2358  1.5.16.1  pgoyette 				       &edid->standard_timings[i]);
   2359       1.1  riastrad 		if (newmode) {
   2360       1.1  riastrad 			drm_mode_probed_add(connector, newmode);
   2361       1.1  riastrad 			modes++;
   2362       1.1  riastrad 		}
   2363       1.1  riastrad 	}
   2364       1.1  riastrad 
   2365       1.1  riastrad 	if (version_greater(edid, 1, 0))
   2366       1.1  riastrad 		drm_for_each_detailed_block((u8 *)edid, do_standard_modes,
   2367       1.1  riastrad 					    &closure);
   2368       1.1  riastrad 
   2369       1.1  riastrad 	/* XXX should also look for standard codes in VTB blocks */
   2370       1.1  riastrad 
   2371       1.1  riastrad 	return modes + closure.modes;
   2372       1.1  riastrad }
   2373       1.1  riastrad 
   2374       1.1  riastrad static int drm_cvt_modes(struct drm_connector *connector,
   2375       1.1  riastrad 			 struct detailed_timing *timing)
   2376       1.1  riastrad {
   2377       1.1  riastrad 	int i, j, modes = 0;
   2378       1.1  riastrad 	struct drm_display_mode *newmode;
   2379       1.1  riastrad 	struct drm_device *dev = connector->dev;
   2380       1.1  riastrad 	struct cvt_timing *cvt;
   2381       1.1  riastrad 	const int rates[] = { 60, 85, 75, 60, 50 };
   2382       1.1  riastrad 	const u8 empty[3] = { 0, 0, 0 };
   2383       1.1  riastrad 
   2384       1.1  riastrad 	for (i = 0; i < 4; i++) {
   2385       1.1  riastrad 		int uninitialized_var(width), height;
   2386       1.1  riastrad 		cvt = &(timing->data.other_data.data.cvt[i]);
   2387       1.1  riastrad 
   2388       1.1  riastrad 		if (!memcmp(cvt->code, empty, 3))
   2389       1.1  riastrad 			continue;
   2390       1.1  riastrad 
   2391       1.1  riastrad 		height = (cvt->code[0] + ((cvt->code[1] & 0xf0) << 4) + 1) * 2;
   2392       1.1  riastrad 		switch (cvt->code[1] & 0x0c) {
   2393       1.1  riastrad 		case 0x00:
   2394       1.1  riastrad 			width = height * 4 / 3;
   2395       1.1  riastrad 			break;
   2396       1.1  riastrad 		case 0x04:
   2397       1.1  riastrad 			width = height * 16 / 9;
   2398       1.1  riastrad 			break;
   2399       1.1  riastrad 		case 0x08:
   2400       1.1  riastrad 			width = height * 16 / 10;
   2401       1.1  riastrad 			break;
   2402       1.1  riastrad 		case 0x0c:
   2403       1.1  riastrad 			width = height * 15 / 9;
   2404       1.1  riastrad 			break;
   2405       1.1  riastrad 		}
   2406       1.1  riastrad 
   2407       1.1  riastrad 		for (j = 1; j < 5; j++) {
   2408       1.1  riastrad 			if (cvt->code[2] & (1 << j)) {
   2409       1.1  riastrad 				newmode = drm_cvt_mode(dev, width, height,
   2410       1.1  riastrad 						       rates[j], j == 0,
   2411       1.1  riastrad 						       false, false);
   2412       1.1  riastrad 				if (newmode) {
   2413       1.1  riastrad 					drm_mode_probed_add(connector, newmode);
   2414       1.1  riastrad 					modes++;
   2415       1.1  riastrad 				}
   2416       1.1  riastrad 			}
   2417       1.1  riastrad 		}
   2418       1.1  riastrad 	}
   2419       1.1  riastrad 
   2420       1.1  riastrad 	return modes;
   2421       1.1  riastrad }
   2422       1.1  riastrad 
   2423       1.1  riastrad static void
   2424       1.1  riastrad do_cvt_mode(struct detailed_timing *timing, void *c)
   2425       1.1  riastrad {
   2426       1.1  riastrad 	struct detailed_mode_closure *closure = c;
   2427       1.1  riastrad 	struct detailed_non_pixel *data = &timing->data.other_data;
   2428       1.1  riastrad 
   2429       1.1  riastrad 	if (data->type == EDID_DETAIL_CVT_3BYTE)
   2430       1.1  riastrad 		closure->modes += drm_cvt_modes(closure->connector, timing);
   2431       1.1  riastrad }
   2432       1.1  riastrad 
   2433       1.1  riastrad static int
   2434       1.1  riastrad add_cvt_modes(struct drm_connector *connector, struct edid *edid)
   2435       1.1  riastrad {
   2436       1.1  riastrad 	struct detailed_mode_closure closure = {
   2437  1.5.16.1  pgoyette 		.connector = connector,
   2438  1.5.16.1  pgoyette 		.edid = edid,
   2439       1.1  riastrad 	};
   2440       1.1  riastrad 
   2441       1.1  riastrad 	if (version_greater(edid, 1, 2))
   2442       1.1  riastrad 		drm_for_each_detailed_block((u8 *)edid, do_cvt_mode, &closure);
   2443       1.1  riastrad 
   2444       1.1  riastrad 	/* XXX should also look for CVT codes in VTB blocks */
   2445       1.1  riastrad 
   2446       1.1  riastrad 	return closure.modes;
   2447       1.1  riastrad }
   2448       1.1  riastrad 
   2449  1.5.16.1  pgoyette static void fixup_detailed_cea_mode_clock(struct drm_display_mode *mode);
   2450  1.5.16.1  pgoyette 
   2451       1.1  riastrad static void
   2452       1.1  riastrad do_detailed_mode(struct detailed_timing *timing, void *c)
   2453       1.1  riastrad {
   2454       1.1  riastrad 	struct detailed_mode_closure *closure = c;
   2455       1.1  riastrad 	struct drm_display_mode *newmode;
   2456       1.1  riastrad 
   2457       1.1  riastrad 	if (timing->pixel_clock) {
   2458       1.1  riastrad 		newmode = drm_mode_detailed(closure->connector->dev,
   2459       1.1  riastrad 					    closure->edid, timing,
   2460       1.1  riastrad 					    closure->quirks);
   2461       1.1  riastrad 		if (!newmode)
   2462       1.1  riastrad 			return;
   2463       1.1  riastrad 
   2464       1.1  riastrad 		if (closure->preferred)
   2465       1.1  riastrad 			newmode->type |= DRM_MODE_TYPE_PREFERRED;
   2466       1.1  riastrad 
   2467  1.5.16.1  pgoyette 		/*
   2468  1.5.16.1  pgoyette 		 * Detailed modes are limited to 10kHz pixel clock resolution,
   2469  1.5.16.1  pgoyette 		 * so fix up anything that looks like CEA/HDMI mode, but the clock
   2470  1.5.16.1  pgoyette 		 * is just slightly off.
   2471  1.5.16.1  pgoyette 		 */
   2472  1.5.16.1  pgoyette 		fixup_detailed_cea_mode_clock(newmode);
   2473  1.5.16.1  pgoyette 
   2474       1.1  riastrad 		drm_mode_probed_add(closure->connector, newmode);
   2475       1.1  riastrad 		closure->modes++;
   2476       1.1  riastrad 		closure->preferred = 0;
   2477       1.1  riastrad 	}
   2478       1.1  riastrad }
   2479       1.1  riastrad 
   2480       1.1  riastrad /*
   2481       1.1  riastrad  * add_detailed_modes - Add modes from detailed timings
   2482       1.1  riastrad  * @connector: attached connector
   2483       1.1  riastrad  * @edid: EDID block to scan
   2484       1.1  riastrad  * @quirks: quirks to apply
   2485       1.1  riastrad  */
   2486       1.1  riastrad static int
   2487       1.1  riastrad add_detailed_modes(struct drm_connector *connector, struct edid *edid,
   2488       1.1  riastrad 		   u32 quirks)
   2489       1.1  riastrad {
   2490       1.1  riastrad 	struct detailed_mode_closure closure = {
   2491  1.5.16.1  pgoyette 		.connector = connector,
   2492  1.5.16.1  pgoyette 		.edid = edid,
   2493  1.5.16.1  pgoyette 		.preferred = 1,
   2494  1.5.16.1  pgoyette 		.quirks = quirks,
   2495       1.1  riastrad 	};
   2496       1.1  riastrad 
   2497       1.1  riastrad 	if (closure.preferred && !version_greater(edid, 1, 3))
   2498       1.1  riastrad 		closure.preferred =
   2499       1.1  riastrad 		    (edid->features & DRM_EDID_FEATURE_PREFERRED_TIMING);
   2500       1.1  riastrad 
   2501       1.1  riastrad 	drm_for_each_detailed_block((u8 *)edid, do_detailed_mode, &closure);
   2502       1.1  riastrad 
   2503       1.1  riastrad 	return closure.modes;
   2504       1.1  riastrad }
   2505       1.1  riastrad 
   2506       1.1  riastrad #define AUDIO_BLOCK	0x01
   2507       1.1  riastrad #define VIDEO_BLOCK     0x02
   2508       1.1  riastrad #define VENDOR_BLOCK    0x03
   2509       1.1  riastrad #define SPEAKER_BLOCK	0x04
   2510       1.3  riastrad #define VIDEO_CAPABILITY_BLOCK	0x07
   2511       1.1  riastrad #define EDID_BASIC_AUDIO	(1 << 6)
   2512       1.1  riastrad #define EDID_CEA_YCRCB444	(1 << 5)
   2513       1.1  riastrad #define EDID_CEA_YCRCB422	(1 << 4)
   2514       1.3  riastrad #define EDID_CEA_VCDB_QS	(1 << 6)
   2515       1.1  riastrad 
   2516       1.3  riastrad /*
   2517       1.1  riastrad  * Search EDID for CEA extension block.
   2518       1.1  riastrad  */
   2519  1.5.16.1  pgoyette static u8 *drm_find_edid_extension(struct edid *edid, int ext_id)
   2520       1.1  riastrad {
   2521       1.1  riastrad 	u8 *edid_ext = NULL;
   2522       1.1  riastrad 	int i;
   2523       1.1  riastrad 
   2524       1.1  riastrad 	/* No EDID or EDID extensions */
   2525       1.1  riastrad 	if (edid == NULL || edid->extensions == 0)
   2526       1.1  riastrad 		return NULL;
   2527       1.1  riastrad 
   2528       1.1  riastrad 	/* Find CEA extension */
   2529       1.1  riastrad 	for (i = 0; i < edid->extensions; i++) {
   2530       1.1  riastrad 		edid_ext = (u8 *)edid + EDID_LENGTH * (i + 1);
   2531  1.5.16.1  pgoyette 		if (edid_ext[0] == ext_id)
   2532       1.1  riastrad 			break;
   2533       1.1  riastrad 	}
   2534       1.1  riastrad 
   2535       1.1  riastrad 	if (i == edid->extensions)
   2536       1.1  riastrad 		return NULL;
   2537       1.1  riastrad 
   2538       1.1  riastrad 	return edid_ext;
   2539       1.1  riastrad }
   2540       1.1  riastrad 
   2541  1.5.16.1  pgoyette static u8 *drm_find_cea_extension(struct edid *edid)
   2542  1.5.16.1  pgoyette {
   2543  1.5.16.1  pgoyette 	return drm_find_edid_extension(edid, CEA_EXT);
   2544  1.5.16.1  pgoyette }
   2545  1.5.16.1  pgoyette 
   2546  1.5.16.1  pgoyette static u8 *drm_find_displayid_extension(struct edid *edid)
   2547  1.5.16.1  pgoyette {
   2548  1.5.16.1  pgoyette 	return drm_find_edid_extension(edid, DISPLAYID_EXT);
   2549  1.5.16.1  pgoyette }
   2550  1.5.16.1  pgoyette 
   2551       1.1  riastrad /*
   2552       1.3  riastrad  * Calculate the alternate clock for the CEA mode
   2553       1.3  riastrad  * (60Hz vs. 59.94Hz etc.)
   2554       1.3  riastrad  */
   2555       1.3  riastrad static unsigned int
   2556       1.3  riastrad cea_mode_alternate_clock(const struct drm_display_mode *cea_mode)
   2557       1.3  riastrad {
   2558       1.3  riastrad 	unsigned int clock = cea_mode->clock;
   2559       1.3  riastrad 
   2560       1.3  riastrad 	if (cea_mode->vrefresh % 6 != 0)
   2561       1.3  riastrad 		return clock;
   2562       1.3  riastrad 
   2563       1.3  riastrad 	/*
   2564       1.3  riastrad 	 * edid_cea_modes contains the 59.94Hz
   2565       1.3  riastrad 	 * variant for 240 and 480 line modes,
   2566       1.3  riastrad 	 * and the 60Hz variant otherwise.
   2567       1.3  riastrad 	 */
   2568       1.3  riastrad 	if (cea_mode->vdisplay == 240 || cea_mode->vdisplay == 480)
   2569  1.5.16.1  pgoyette 		clock = DIV_ROUND_CLOSEST(clock * 1001, 1000);
   2570       1.3  riastrad 	else
   2571  1.5.16.1  pgoyette 		clock = DIV_ROUND_CLOSEST(clock * 1000, 1001);
   2572       1.3  riastrad 
   2573       1.3  riastrad 	return clock;
   2574       1.3  riastrad }
   2575       1.3  riastrad 
   2576       1.3  riastrad /**
   2577       1.3  riastrad  * drm_match_cea_mode - look for a CEA mode matching given mode
   2578       1.3  riastrad  * @to_match: display mode
   2579       1.3  riastrad  *
   2580  1.5.16.1  pgoyette  * Return: The CEA Video ID (VIC) of the mode or 0 if it isn't a CEA-861
   2581       1.3  riastrad  * mode.
   2582       1.1  riastrad  */
   2583       1.3  riastrad u8 drm_match_cea_mode(const struct drm_display_mode *to_match)
   2584       1.1  riastrad {
   2585       1.1  riastrad 	u8 mode;
   2586       1.1  riastrad 
   2587       1.3  riastrad 	if (!to_match->clock)
   2588       1.3  riastrad 		return 0;
   2589       1.1  riastrad 
   2590       1.3  riastrad 	for (mode = 0; mode < ARRAY_SIZE(edid_cea_modes); mode++) {
   2591       1.3  riastrad 		const struct drm_display_mode *cea_mode = &edid_cea_modes[mode];
   2592       1.3  riastrad 		unsigned int clock1, clock2;
   2593       1.3  riastrad 
   2594       1.3  riastrad 		/* Check both 60Hz and 59.94Hz */
   2595       1.3  riastrad 		clock1 = cea_mode->clock;
   2596       1.3  riastrad 		clock2 = cea_mode_alternate_clock(cea_mode);
   2597       1.3  riastrad 
   2598       1.3  riastrad 		if ((KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock1) ||
   2599       1.3  riastrad 		     KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock2)) &&
   2600       1.3  riastrad 		    drm_mode_equal_no_clocks_no_stereo(to_match, cea_mode))
   2601       1.1  riastrad 			return mode + 1;
   2602       1.1  riastrad 	}
   2603       1.1  riastrad 	return 0;
   2604       1.1  riastrad }
   2605       1.1  riastrad EXPORT_SYMBOL(drm_match_cea_mode);
   2606       1.1  riastrad 
   2607  1.5.16.1  pgoyette /**
   2608  1.5.16.1  pgoyette  * drm_get_cea_aspect_ratio - get the picture aspect ratio corresponding to
   2609  1.5.16.1  pgoyette  * the input VIC from the CEA mode list
   2610  1.5.16.1  pgoyette  * @video_code: ID given to each of the CEA modes
   2611  1.5.16.1  pgoyette  *
   2612  1.5.16.1  pgoyette  * Returns picture aspect ratio
   2613  1.5.16.1  pgoyette  */
   2614  1.5.16.1  pgoyette enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code)
   2615  1.5.16.1  pgoyette {
   2616  1.5.16.1  pgoyette 	/* return picture aspect ratio for video_code - 1 to access the
   2617  1.5.16.1  pgoyette 	 * right array element
   2618  1.5.16.1  pgoyette 	*/
   2619  1.5.16.1  pgoyette 	return edid_cea_modes[video_code-1].picture_aspect_ratio;
   2620  1.5.16.1  pgoyette }
   2621  1.5.16.1  pgoyette EXPORT_SYMBOL(drm_get_cea_aspect_ratio);
   2622  1.5.16.1  pgoyette 
   2623       1.3  riastrad /*
   2624       1.3  riastrad  * Calculate the alternate clock for HDMI modes (those from the HDMI vendor
   2625       1.3  riastrad  * specific block).
   2626       1.3  riastrad  *
   2627       1.3  riastrad  * It's almost like cea_mode_alternate_clock(), we just need to add an
   2628       1.3  riastrad  * exception for the VIC 4 mode (4096x2160@24Hz): no alternate clock for this
   2629       1.3  riastrad  * one.
   2630       1.3  riastrad  */
   2631       1.3  riastrad static unsigned int
   2632       1.3  riastrad hdmi_mode_alternate_clock(const struct drm_display_mode *hdmi_mode)
   2633       1.3  riastrad {
   2634       1.3  riastrad 	if (hdmi_mode->vdisplay == 4096 && hdmi_mode->hdisplay == 2160)
   2635       1.3  riastrad 		return hdmi_mode->clock;
   2636       1.3  riastrad 
   2637       1.3  riastrad 	return cea_mode_alternate_clock(hdmi_mode);
   2638       1.3  riastrad }
   2639       1.3  riastrad 
   2640       1.3  riastrad /*
   2641       1.3  riastrad  * drm_match_hdmi_mode - look for a HDMI mode matching given mode
   2642       1.3  riastrad  * @to_match: display mode
   2643       1.3  riastrad  *
   2644       1.3  riastrad  * An HDMI mode is one defined in the HDMI vendor specific block.
   2645       1.3  riastrad  *
   2646       1.3  riastrad  * Returns the HDMI Video ID (VIC) of the mode or 0 if it isn't one.
   2647       1.3  riastrad  */
   2648       1.3  riastrad static u8 drm_match_hdmi_mode(const struct drm_display_mode *to_match)
   2649       1.3  riastrad {
   2650       1.3  riastrad 	u8 mode;
   2651       1.3  riastrad 
   2652       1.3  riastrad 	if (!to_match->clock)
   2653       1.3  riastrad 		return 0;
   2654       1.3  riastrad 
   2655       1.3  riastrad 	for (mode = 0; mode < ARRAY_SIZE(edid_4k_modes); mode++) {
   2656       1.3  riastrad 		const struct drm_display_mode *hdmi_mode = &edid_4k_modes[mode];
   2657       1.3  riastrad 		unsigned int clock1, clock2;
   2658       1.3  riastrad 
   2659       1.3  riastrad 		/* Make sure to also match alternate clocks */
   2660       1.3  riastrad 		clock1 = hdmi_mode->clock;
   2661       1.3  riastrad 		clock2 = hdmi_mode_alternate_clock(hdmi_mode);
   2662       1.3  riastrad 
   2663       1.3  riastrad 		if ((KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock1) ||
   2664       1.3  riastrad 		     KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock2)) &&
   2665       1.3  riastrad 		    drm_mode_equal_no_clocks_no_stereo(to_match, hdmi_mode))
   2666       1.3  riastrad 			return mode + 1;
   2667       1.3  riastrad 	}
   2668       1.3  riastrad 	return 0;
   2669       1.3  riastrad }
   2670       1.1  riastrad 
   2671       1.1  riastrad static int
   2672       1.3  riastrad add_alternate_cea_modes(struct drm_connector *connector, struct edid *edid)
   2673       1.1  riastrad {
   2674       1.1  riastrad 	struct drm_device *dev = connector->dev;
   2675       1.3  riastrad 	struct drm_display_mode *mode, *tmp;
   2676       1.4  riastrad 	struct list_head list = LIST_HEAD_INIT(list);
   2677       1.1  riastrad 	int modes = 0;
   2678       1.1  riastrad 
   2679       1.3  riastrad 	/* Don't add CEA modes if the CEA extension block is missing */
   2680       1.3  riastrad 	if (!drm_find_cea_extension(edid))
   2681       1.3  riastrad 		return 0;
   2682       1.3  riastrad 
   2683       1.3  riastrad 	/*
   2684       1.3  riastrad 	 * Go through all probed modes and create a new mode
   2685       1.3  riastrad 	 * with the alternate clock for certain CEA modes.
   2686       1.3  riastrad 	 */
   2687       1.3  riastrad 	list_for_each_entry(mode, &connector->probed_modes, head) {
   2688       1.3  riastrad 		const struct drm_display_mode *cea_mode = NULL;
   2689       1.3  riastrad 		struct drm_display_mode *newmode;
   2690       1.3  riastrad 		u8 mode_idx = drm_match_cea_mode(mode) - 1;
   2691       1.3  riastrad 		unsigned int clock1, clock2;
   2692       1.3  riastrad 
   2693       1.3  riastrad 		if (mode_idx < ARRAY_SIZE(edid_cea_modes)) {
   2694       1.3  riastrad 			cea_mode = &edid_cea_modes[mode_idx];
   2695       1.3  riastrad 			clock2 = cea_mode_alternate_clock(cea_mode);
   2696       1.3  riastrad 		} else {
   2697       1.3  riastrad 			mode_idx = drm_match_hdmi_mode(mode) - 1;
   2698       1.3  riastrad 			if (mode_idx < ARRAY_SIZE(edid_4k_modes)) {
   2699       1.3  riastrad 				cea_mode = &edid_4k_modes[mode_idx];
   2700       1.3  riastrad 				clock2 = hdmi_mode_alternate_clock(cea_mode);
   2701       1.3  riastrad 			}
   2702       1.3  riastrad 		}
   2703       1.3  riastrad 
   2704       1.3  riastrad 		if (!cea_mode)
   2705       1.3  riastrad 			continue;
   2706       1.3  riastrad 
   2707       1.3  riastrad 		clock1 = cea_mode->clock;
   2708       1.3  riastrad 
   2709       1.3  riastrad 		if (clock1 == clock2)
   2710       1.3  riastrad 			continue;
   2711       1.3  riastrad 
   2712       1.3  riastrad 		if (mode->clock != clock1 && mode->clock != clock2)
   2713       1.3  riastrad 			continue;
   2714       1.3  riastrad 
   2715       1.3  riastrad 		newmode = drm_mode_duplicate(dev, cea_mode);
   2716       1.3  riastrad 		if (!newmode)
   2717       1.3  riastrad 			continue;
   2718       1.3  riastrad 
   2719       1.3  riastrad 		/* Carry over the stereo flags */
   2720       1.3  riastrad 		newmode->flags |= mode->flags & DRM_MODE_FLAG_3D_MASK;
   2721       1.3  riastrad 
   2722       1.3  riastrad 		/*
   2723       1.3  riastrad 		 * The current mode could be either variant. Make
   2724       1.3  riastrad 		 * sure to pick the "other" clock for the new mode.
   2725       1.3  riastrad 		 */
   2726       1.3  riastrad 		if (mode->clock != clock1)
   2727       1.3  riastrad 			newmode->clock = clock1;
   2728       1.3  riastrad 		else
   2729       1.3  riastrad 			newmode->clock = clock2;
   2730       1.3  riastrad 
   2731       1.3  riastrad 		list_add_tail(&newmode->head, &list);
   2732       1.3  riastrad 	}
   2733       1.3  riastrad 
   2734       1.3  riastrad 	list_for_each_entry_safe(mode, tmp, &list, head) {
   2735       1.3  riastrad 		list_del(&mode->head);
   2736       1.3  riastrad 		drm_mode_probed_add(connector, mode);
   2737       1.3  riastrad 		modes++;
   2738       1.3  riastrad 	}
   2739       1.3  riastrad 
   2740       1.3  riastrad 	return modes;
   2741       1.3  riastrad }
   2742       1.3  riastrad 
   2743       1.3  riastrad static struct drm_display_mode *
   2744       1.3  riastrad drm_display_mode_from_vic_index(struct drm_connector *connector,
   2745       1.3  riastrad 				const u8 *video_db, u8 video_len,
   2746       1.3  riastrad 				u8 video_index)
   2747       1.3  riastrad {
   2748       1.3  riastrad 	struct drm_device *dev = connector->dev;
   2749       1.3  riastrad 	struct drm_display_mode *newmode;
   2750       1.3  riastrad 	u8 cea_mode;
   2751       1.3  riastrad 
   2752       1.3  riastrad 	if (video_db == NULL || video_index >= video_len)
   2753       1.3  riastrad 		return NULL;
   2754       1.3  riastrad 
   2755       1.3  riastrad 	/* CEA modes are numbered 1..127 */
   2756       1.3  riastrad 	cea_mode = (video_db[video_index] & 127) - 1;
   2757       1.3  riastrad 	if (cea_mode >= ARRAY_SIZE(edid_cea_modes))
   2758       1.3  riastrad 		return NULL;
   2759       1.3  riastrad 
   2760       1.3  riastrad 	newmode = drm_mode_duplicate(dev, &edid_cea_modes[cea_mode]);
   2761       1.3  riastrad 	if (!newmode)
   2762       1.3  riastrad 		return NULL;
   2763       1.3  riastrad 
   2764       1.3  riastrad 	newmode->vrefresh = 0;
   2765       1.3  riastrad 
   2766       1.3  riastrad 	return newmode;
   2767       1.3  riastrad }
   2768       1.3  riastrad 
   2769       1.3  riastrad static int
   2770       1.3  riastrad do_cea_modes(struct drm_connector *connector, const u8 *db, u8 len)
   2771       1.3  riastrad {
   2772       1.3  riastrad 	int i, modes = 0;
   2773       1.3  riastrad 
   2774       1.3  riastrad 	for (i = 0; i < len; i++) {
   2775       1.3  riastrad 		struct drm_display_mode *mode;
   2776       1.3  riastrad 		mode = drm_display_mode_from_vic_index(connector, db, len, i);
   2777       1.3  riastrad 		if (mode) {
   2778       1.3  riastrad 			drm_mode_probed_add(connector, mode);
   2779       1.3  riastrad 			modes++;
   2780       1.3  riastrad 		}
   2781       1.3  riastrad 	}
   2782       1.3  riastrad 
   2783       1.3  riastrad 	return modes;
   2784       1.3  riastrad }
   2785       1.3  riastrad 
   2786       1.3  riastrad struct stereo_mandatory_mode {
   2787       1.3  riastrad 	int width, height, vrefresh;
   2788       1.3  riastrad 	unsigned int flags;
   2789       1.3  riastrad };
   2790       1.3  riastrad 
   2791       1.3  riastrad static const struct stereo_mandatory_mode stereo_mandatory_modes[] = {
   2792       1.3  riastrad 	{ 1920, 1080, 24, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
   2793       1.3  riastrad 	{ 1920, 1080, 24, DRM_MODE_FLAG_3D_FRAME_PACKING },
   2794       1.3  riastrad 	{ 1920, 1080, 50,
   2795       1.3  riastrad 	  DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF },
   2796       1.3  riastrad 	{ 1920, 1080, 60,
   2797       1.3  riastrad 	  DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF },
   2798       1.3  riastrad 	{ 1280, 720,  50, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
   2799       1.3  riastrad 	{ 1280, 720,  50, DRM_MODE_FLAG_3D_FRAME_PACKING },
   2800       1.3  riastrad 	{ 1280, 720,  60, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
   2801       1.3  riastrad 	{ 1280, 720,  60, DRM_MODE_FLAG_3D_FRAME_PACKING }
   2802       1.3  riastrad };
   2803       1.3  riastrad 
   2804       1.3  riastrad static bool
   2805       1.3  riastrad stereo_match_mandatory(const struct drm_display_mode *mode,
   2806       1.3  riastrad 		       const struct stereo_mandatory_mode *stereo_mode)
   2807       1.3  riastrad {
   2808       1.3  riastrad 	unsigned int interlaced = mode->flags & DRM_MODE_FLAG_INTERLACE;
   2809       1.3  riastrad 
   2810       1.3  riastrad 	return mode->hdisplay == stereo_mode->width &&
   2811       1.3  riastrad 	       mode->vdisplay == stereo_mode->height &&
   2812       1.3  riastrad 	       interlaced == (stereo_mode->flags & DRM_MODE_FLAG_INTERLACE) &&
   2813       1.3  riastrad 	       drm_mode_vrefresh(mode) == stereo_mode->vrefresh;
   2814       1.3  riastrad }
   2815       1.3  riastrad 
   2816       1.3  riastrad static int add_hdmi_mandatory_stereo_modes(struct drm_connector *connector)
   2817       1.3  riastrad {
   2818       1.3  riastrad 	struct drm_device *dev = connector->dev;
   2819       1.3  riastrad 	const struct drm_display_mode *mode;
   2820       1.3  riastrad 	struct list_head stereo_modes;
   2821       1.3  riastrad 	int modes = 0, i;
   2822       1.3  riastrad 
   2823       1.3  riastrad 	INIT_LIST_HEAD(&stereo_modes);
   2824       1.3  riastrad 
   2825       1.3  riastrad 	list_for_each_entry(mode, &connector->probed_modes, head) {
   2826       1.3  riastrad 		for (i = 0; i < ARRAY_SIZE(stereo_mandatory_modes); i++) {
   2827       1.3  riastrad 			const struct stereo_mandatory_mode *mandatory;
   2828       1.3  riastrad 			struct drm_display_mode *new_mode;
   2829       1.3  riastrad 
   2830       1.3  riastrad 			if (!stereo_match_mandatory(mode,
   2831       1.3  riastrad 						    &stereo_mandatory_modes[i]))
   2832       1.3  riastrad 				continue;
   2833       1.3  riastrad 
   2834       1.3  riastrad 			mandatory = &stereo_mandatory_modes[i];
   2835       1.3  riastrad 			new_mode = drm_mode_duplicate(dev, mode);
   2836       1.3  riastrad 			if (!new_mode)
   2837       1.3  riastrad 				continue;
   2838       1.3  riastrad 
   2839       1.3  riastrad 			new_mode->flags |= mandatory->flags;
   2840       1.3  riastrad 			list_add_tail(&new_mode->head, &stereo_modes);
   2841       1.3  riastrad 			modes++;
   2842       1.3  riastrad 		}
   2843       1.3  riastrad 	}
   2844       1.3  riastrad 
   2845       1.3  riastrad 	list_splice_tail(&stereo_modes, &connector->probed_modes);
   2846       1.3  riastrad 
   2847       1.3  riastrad 	return modes;
   2848       1.3  riastrad }
   2849       1.3  riastrad 
   2850       1.3  riastrad static int add_hdmi_mode(struct drm_connector *connector, u8 vic)
   2851       1.3  riastrad {
   2852       1.3  riastrad 	struct drm_device *dev = connector->dev;
   2853       1.3  riastrad 	struct drm_display_mode *newmode;
   2854       1.3  riastrad 
   2855       1.3  riastrad 	vic--; /* VICs start at 1 */
   2856       1.3  riastrad 	if (vic >= ARRAY_SIZE(edid_4k_modes)) {
   2857       1.3  riastrad 		DRM_ERROR("Unknown HDMI VIC: %d\n", vic);
   2858       1.3  riastrad 		return 0;
   2859       1.3  riastrad 	}
   2860       1.3  riastrad 
   2861       1.3  riastrad 	newmode = drm_mode_duplicate(dev, &edid_4k_modes[vic]);
   2862       1.3  riastrad 	if (!newmode)
   2863       1.3  riastrad 		return 0;
   2864       1.3  riastrad 
   2865       1.3  riastrad 	drm_mode_probed_add(connector, newmode);
   2866       1.3  riastrad 
   2867       1.3  riastrad 	return 1;
   2868       1.3  riastrad }
   2869       1.3  riastrad 
   2870       1.3  riastrad static int add_3d_struct_modes(struct drm_connector *connector, u16 structure,
   2871       1.3  riastrad 			       const u8 *video_db, u8 video_len, u8 video_index)
   2872       1.3  riastrad {
   2873       1.3  riastrad 	struct drm_display_mode *newmode;
   2874       1.3  riastrad 	int modes = 0;
   2875       1.3  riastrad 
   2876       1.3  riastrad 	if (structure & (1 << 0)) {
   2877       1.3  riastrad 		newmode = drm_display_mode_from_vic_index(connector, video_db,
   2878       1.3  riastrad 							  video_len,
   2879       1.3  riastrad 							  video_index);
   2880       1.3  riastrad 		if (newmode) {
   2881       1.3  riastrad 			newmode->flags |= DRM_MODE_FLAG_3D_FRAME_PACKING;
   2882       1.3  riastrad 			drm_mode_probed_add(connector, newmode);
   2883       1.3  riastrad 			modes++;
   2884       1.3  riastrad 		}
   2885       1.3  riastrad 	}
   2886       1.3  riastrad 	if (structure & (1 << 6)) {
   2887       1.3  riastrad 		newmode = drm_display_mode_from_vic_index(connector, video_db,
   2888       1.3  riastrad 							  video_len,
   2889       1.3  riastrad 							  video_index);
   2890       1.3  riastrad 		if (newmode) {
   2891       1.3  riastrad 			newmode->flags |= DRM_MODE_FLAG_3D_TOP_AND_BOTTOM;
   2892       1.3  riastrad 			drm_mode_probed_add(connector, newmode);
   2893       1.3  riastrad 			modes++;
   2894       1.3  riastrad 		}
   2895       1.3  riastrad 	}
   2896       1.3  riastrad 	if (structure & (1 << 8)) {
   2897       1.3  riastrad 		newmode = drm_display_mode_from_vic_index(connector, video_db,
   2898       1.3  riastrad 							  video_len,
   2899       1.3  riastrad 							  video_index);
   2900       1.3  riastrad 		if (newmode) {
   2901       1.3  riastrad 			newmode->flags |= DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF;
   2902       1.3  riastrad 			drm_mode_probed_add(connector, newmode);
   2903       1.3  riastrad 			modes++;
   2904       1.3  riastrad 		}
   2905       1.3  riastrad 	}
   2906       1.3  riastrad 
   2907       1.3  riastrad 	return modes;
   2908       1.3  riastrad }
   2909       1.3  riastrad 
   2910       1.3  riastrad /*
   2911       1.3  riastrad  * do_hdmi_vsdb_modes - Parse the HDMI Vendor Specific data block
   2912       1.3  riastrad  * @connector: connector corresponding to the HDMI sink
   2913       1.3  riastrad  * @db: start of the CEA vendor specific block
   2914       1.3  riastrad  * @len: length of the CEA block payload, ie. one can access up to db[len]
   2915       1.3  riastrad  *
   2916       1.3  riastrad  * Parses the HDMI VSDB looking for modes to add to @connector. This function
   2917       1.3  riastrad  * also adds the stereo 3d modes when applicable.
   2918       1.3  riastrad  */
   2919       1.3  riastrad static int
   2920       1.3  riastrad do_hdmi_vsdb_modes(struct drm_connector *connector, const u8 *db, u8 len,
   2921       1.3  riastrad 		   const u8 *video_db, u8 video_len)
   2922       1.3  riastrad {
   2923       1.3  riastrad 	int modes = 0, offset = 0, i, multi_present = 0, multi_len;
   2924       1.3  riastrad 	u8 vic_len, hdmi_3d_len = 0;
   2925       1.3  riastrad 	u16 mask;
   2926       1.3  riastrad 	u16 structure_all;
   2927       1.3  riastrad 
   2928       1.3  riastrad 	if (len < 8)
   2929       1.3  riastrad 		goto out;
   2930       1.3  riastrad 
   2931       1.3  riastrad 	/* no HDMI_Video_Present */
   2932       1.3  riastrad 	if (!(db[8] & (1 << 5)))
   2933       1.3  riastrad 		goto out;
   2934       1.3  riastrad 
   2935       1.3  riastrad 	/* Latency_Fields_Present */
   2936       1.3  riastrad 	if (db[8] & (1 << 7))
   2937       1.3  riastrad 		offset += 2;
   2938       1.3  riastrad 
   2939       1.3  riastrad 	/* I_Latency_Fields_Present */
   2940       1.3  riastrad 	if (db[8] & (1 << 6))
   2941       1.3  riastrad 		offset += 2;
   2942       1.3  riastrad 
   2943       1.3  riastrad 	/* the declared length is not long enough for the 2 first bytes
   2944       1.3  riastrad 	 * of additional video format capabilities */
   2945       1.3  riastrad 	if (len < (8 + offset + 2))
   2946       1.3  riastrad 		goto out;
   2947       1.3  riastrad 
   2948       1.3  riastrad 	/* 3D_Present */
   2949       1.3  riastrad 	offset++;
   2950       1.3  riastrad 	if (db[8 + offset] & (1 << 7)) {
   2951       1.3  riastrad 		modes += add_hdmi_mandatory_stereo_modes(connector);
   2952       1.3  riastrad 
   2953       1.3  riastrad 		/* 3D_Multi_present */
   2954       1.3  riastrad 		multi_present = (db[8 + offset] & 0x60) >> 5;
   2955       1.3  riastrad 	}
   2956       1.3  riastrad 
   2957       1.3  riastrad 	offset++;
   2958       1.3  riastrad 	vic_len = db[8 + offset] >> 5;
   2959       1.3  riastrad 	hdmi_3d_len = db[8 + offset] & 0x1f;
   2960       1.3  riastrad 
   2961       1.3  riastrad 	for (i = 0; i < vic_len && len >= (9 + offset + i); i++) {
   2962       1.3  riastrad 		u8 vic;
   2963       1.3  riastrad 
   2964       1.3  riastrad 		vic = db[9 + offset + i];
   2965       1.3  riastrad 		modes += add_hdmi_mode(connector, vic);
   2966       1.3  riastrad 	}
   2967       1.3  riastrad 	offset += 1 + vic_len;
   2968       1.3  riastrad 
   2969       1.3  riastrad 	if (multi_present == 1)
   2970       1.3  riastrad 		multi_len = 2;
   2971       1.3  riastrad 	else if (multi_present == 2)
   2972       1.3  riastrad 		multi_len = 4;
   2973       1.3  riastrad 	else
   2974       1.3  riastrad 		multi_len = 0;
   2975       1.3  riastrad 
   2976       1.3  riastrad 	if (len < (8 + offset + hdmi_3d_len - 1))
   2977       1.3  riastrad 		goto out;
   2978       1.3  riastrad 
   2979       1.3  riastrad 	if (hdmi_3d_len < multi_len)
   2980       1.3  riastrad 		goto out;
   2981       1.3  riastrad 
   2982       1.3  riastrad 	if (multi_present == 1 || multi_present == 2) {
   2983       1.3  riastrad 		/* 3D_Structure_ALL */
   2984       1.3  riastrad 		structure_all = (db[8 + offset] << 8) | db[9 + offset];
   2985       1.3  riastrad 
   2986       1.3  riastrad 		/* check if 3D_MASK is present */
   2987       1.3  riastrad 		if (multi_present == 2)
   2988       1.3  riastrad 			mask = (db[10 + offset] << 8) | db[11 + offset];
   2989       1.3  riastrad 		else
   2990       1.3  riastrad 			mask = 0xffff;
   2991       1.3  riastrad 
   2992       1.3  riastrad 		for (i = 0; i < 16; i++) {
   2993       1.3  riastrad 			if (mask & (1 << i))
   2994       1.3  riastrad 				modes += add_3d_struct_modes(connector,
   2995       1.3  riastrad 						structure_all,
   2996       1.3  riastrad 						video_db,
   2997       1.3  riastrad 						video_len, i);
   2998       1.3  riastrad 		}
   2999       1.3  riastrad 	}
   3000       1.3  riastrad 
   3001       1.3  riastrad 	offset += multi_len;
   3002       1.3  riastrad 
   3003       1.3  riastrad 	for (i = 0; i < (hdmi_3d_len - multi_len); i++) {
   3004       1.3  riastrad 		int vic_index;
   3005       1.3  riastrad 		struct drm_display_mode *newmode = NULL;
   3006       1.3  riastrad 		unsigned int newflag = 0;
   3007       1.3  riastrad 		bool detail_present;
   3008       1.3  riastrad 
   3009       1.3  riastrad 		detail_present = ((db[8 + offset + i] & 0x0f) > 7);
   3010       1.3  riastrad 
   3011       1.3  riastrad 		if (detail_present && (i + 1 == hdmi_3d_len - multi_len))
   3012       1.3  riastrad 			break;
   3013       1.3  riastrad 
   3014       1.3  riastrad 		/* 2D_VIC_order_X */
   3015       1.3  riastrad 		vic_index = db[8 + offset + i] >> 4;
   3016       1.3  riastrad 
   3017       1.3  riastrad 		/* 3D_Structure_X */
   3018       1.3  riastrad 		switch (db[8 + offset + i] & 0x0f) {
   3019       1.3  riastrad 		case 0:
   3020       1.3  riastrad 			newflag = DRM_MODE_FLAG_3D_FRAME_PACKING;
   3021       1.3  riastrad 			break;
   3022       1.3  riastrad 		case 6:
   3023       1.3  riastrad 			newflag = DRM_MODE_FLAG_3D_TOP_AND_BOTTOM;
   3024       1.3  riastrad 			break;
   3025       1.3  riastrad 		case 8:
   3026       1.3  riastrad 			/* 3D_Detail_X */
   3027       1.3  riastrad 			if ((db[9 + offset + i] >> 4) == 1)
   3028       1.3  riastrad 				newflag = DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF;
   3029       1.3  riastrad 			break;
   3030       1.3  riastrad 		}
   3031       1.3  riastrad 
   3032       1.3  riastrad 		if (newflag != 0) {
   3033       1.3  riastrad 			newmode = drm_display_mode_from_vic_index(connector,
   3034       1.3  riastrad 								  video_db,
   3035       1.3  riastrad 								  video_len,
   3036       1.3  riastrad 								  vic_index);
   3037       1.3  riastrad 
   3038       1.1  riastrad 			if (newmode) {
   3039       1.3  riastrad 				newmode->flags |= newflag;
   3040       1.1  riastrad 				drm_mode_probed_add(connector, newmode);
   3041       1.1  riastrad 				modes++;
   3042       1.1  riastrad 			}
   3043       1.1  riastrad 		}
   3044       1.3  riastrad 
   3045       1.3  riastrad 		if (detail_present)
   3046       1.3  riastrad 			i++;
   3047       1.1  riastrad 	}
   3048       1.1  riastrad 
   3049       1.3  riastrad out:
   3050       1.1  riastrad 	return modes;
   3051       1.1  riastrad }
   3052       1.1  riastrad 
   3053       1.1  riastrad static int
   3054       1.1  riastrad cea_db_payload_len(const u8 *db)
   3055       1.1  riastrad {
   3056       1.1  riastrad 	return db[0] & 0x1f;
   3057       1.1  riastrad }
   3058       1.1  riastrad 
   3059       1.1  riastrad static int
   3060       1.1  riastrad cea_db_tag(const u8 *db)
   3061       1.1  riastrad {
   3062       1.1  riastrad 	return db[0] >> 5;
   3063       1.1  riastrad }
   3064       1.1  riastrad 
   3065       1.1  riastrad static int
   3066       1.1  riastrad cea_revision(const u8 *cea)
   3067       1.1  riastrad {
   3068       1.1  riastrad 	return cea[1];
   3069       1.1  riastrad }
   3070       1.1  riastrad 
   3071       1.1  riastrad static int
   3072       1.1  riastrad cea_db_offsets(const u8 *cea, int *start, int *end)
   3073       1.1  riastrad {
   3074       1.1  riastrad 	/* Data block offset in CEA extension block */
   3075       1.1  riastrad 	*start = 4;
   3076       1.1  riastrad 	*end = cea[2];
   3077       1.1  riastrad 	if (*end == 0)
   3078       1.1  riastrad 		*end = 127;
   3079       1.1  riastrad 	if (*end < 4 || *end > 127)
   3080       1.1  riastrad 		return -ERANGE;
   3081       1.1  riastrad 	return 0;
   3082       1.1  riastrad }
   3083       1.1  riastrad 
   3084       1.3  riastrad static bool cea_db_is_hdmi_vsdb(const u8 *db)
   3085       1.3  riastrad {
   3086       1.3  riastrad 	int hdmi_id;
   3087       1.3  riastrad 
   3088       1.3  riastrad 	if (cea_db_tag(db) != VENDOR_BLOCK)
   3089       1.3  riastrad 		return false;
   3090       1.3  riastrad 
   3091       1.3  riastrad 	if (cea_db_payload_len(db) < 5)
   3092       1.3  riastrad 		return false;
   3093       1.3  riastrad 
   3094       1.3  riastrad 	hdmi_id = db[1] | (db[2] << 8) | (db[3] << 16);
   3095       1.3  riastrad 
   3096       1.3  riastrad 	return hdmi_id == HDMI_IEEE_OUI;
   3097       1.3  riastrad }
   3098       1.3  riastrad 
   3099       1.1  riastrad #define for_each_cea_db(cea, i, start, end) \
   3100       1.1  riastrad 	for ((i) = (start); (i) < (end) && (i) + cea_db_payload_len(&(cea)[(i)]) < (end); (i) += cea_db_payload_len(&(cea)[(i)]) + 1)
   3101       1.1  riastrad 
   3102       1.1  riastrad static int
   3103       1.1  riastrad add_cea_modes(struct drm_connector *connector, struct edid *edid)
   3104       1.1  riastrad {
   3105       1.3  riastrad 	const u8 *cea = drm_find_cea_extension(edid);
   3106       1.3  riastrad 	const u8 *db, *hdmi = NULL, *video = NULL;
   3107       1.3  riastrad 	u8 dbl, hdmi_len, video_len = 0;
   3108       1.1  riastrad 	int modes = 0;
   3109       1.1  riastrad 
   3110       1.1  riastrad 	if (cea && cea_revision(cea) >= 3) {
   3111       1.1  riastrad 		int i, start, end;
   3112       1.1  riastrad 
   3113       1.1  riastrad 		if (cea_db_offsets(cea, &start, &end))
   3114       1.1  riastrad 			return 0;
   3115       1.1  riastrad 
   3116       1.1  riastrad 		for_each_cea_db(cea, i, start, end) {
   3117       1.1  riastrad 			db = &cea[i];
   3118       1.1  riastrad 			dbl = cea_db_payload_len(db);
   3119       1.1  riastrad 
   3120       1.3  riastrad 			if (cea_db_tag(db) == VIDEO_BLOCK) {
   3121       1.3  riastrad 				video = db + 1;
   3122       1.3  riastrad 				video_len = dbl;
   3123       1.3  riastrad 				modes += do_cea_modes(connector, video, dbl);
   3124       1.3  riastrad 			}
   3125       1.3  riastrad 			else if (cea_db_is_hdmi_vsdb(db)) {
   3126       1.3  riastrad 				hdmi = db;
   3127       1.3  riastrad 				hdmi_len = dbl;
   3128       1.3  riastrad 			}
   3129       1.1  riastrad 		}
   3130       1.1  riastrad 	}
   3131       1.1  riastrad 
   3132       1.3  riastrad 	/*
   3133       1.3  riastrad 	 * We parse the HDMI VSDB after having added the cea modes as we will
   3134       1.3  riastrad 	 * be patching their flags when the sink supports stereo 3D.
   3135       1.3  riastrad 	 */
   3136       1.3  riastrad 	if (hdmi)
   3137       1.3  riastrad 		modes += do_hdmi_vsdb_modes(connector, hdmi, hdmi_len, video,
   3138       1.3  riastrad 					    video_len);
   3139       1.3  riastrad 
   3140       1.1  riastrad 	return modes;
   3141       1.1  riastrad }
   3142       1.1  riastrad 
   3143  1.5.16.1  pgoyette static void fixup_detailed_cea_mode_clock(struct drm_display_mode *mode)
   3144  1.5.16.1  pgoyette {
   3145  1.5.16.1  pgoyette 	const struct drm_display_mode *cea_mode;
   3146  1.5.16.1  pgoyette 	int clock1, clock2, clock;
   3147  1.5.16.1  pgoyette 	u8 mode_idx;
   3148  1.5.16.1  pgoyette 	const char *type;
   3149  1.5.16.1  pgoyette 
   3150  1.5.16.1  pgoyette 	mode_idx = drm_match_cea_mode(mode) - 1;
   3151  1.5.16.1  pgoyette 	if (mode_idx < ARRAY_SIZE(edid_cea_modes)) {
   3152  1.5.16.1  pgoyette 		type = "CEA";
   3153  1.5.16.1  pgoyette 		cea_mode = &edid_cea_modes[mode_idx];
   3154  1.5.16.1  pgoyette 		clock1 = cea_mode->clock;
   3155  1.5.16.1  pgoyette 		clock2 = cea_mode_alternate_clock(cea_mode);
   3156  1.5.16.1  pgoyette 	} else {
   3157  1.5.16.1  pgoyette 		mode_idx = drm_match_hdmi_mode(mode) - 1;
   3158  1.5.16.1  pgoyette 		if (mode_idx < ARRAY_SIZE(edid_4k_modes)) {
   3159  1.5.16.1  pgoyette 			type = "HDMI";
   3160  1.5.16.1  pgoyette 			cea_mode = &edid_4k_modes[mode_idx];
   3161  1.5.16.1  pgoyette 			clock1 = cea_mode->clock;
   3162  1.5.16.1  pgoyette 			clock2 = hdmi_mode_alternate_clock(cea_mode);
   3163  1.5.16.1  pgoyette 		} else {
   3164  1.5.16.1  pgoyette 			return;
   3165  1.5.16.1  pgoyette 		}
   3166  1.5.16.1  pgoyette 	}
   3167  1.5.16.1  pgoyette 
   3168  1.5.16.1  pgoyette 	/* pick whichever is closest */
   3169  1.5.16.1  pgoyette 	if (abs(mode->clock - clock1) < abs(mode->clock - clock2))
   3170  1.5.16.1  pgoyette 		clock = clock1;
   3171  1.5.16.1  pgoyette 	else
   3172  1.5.16.1  pgoyette 		clock = clock2;
   3173  1.5.16.1  pgoyette 
   3174  1.5.16.1  pgoyette 	if (mode->clock == clock)
   3175  1.5.16.1  pgoyette 		return;
   3176  1.5.16.1  pgoyette 
   3177  1.5.16.1  pgoyette 	DRM_DEBUG("detailed mode matches %s VIC %d, adjusting clock %d -> %d\n",
   3178  1.5.16.1  pgoyette 		  type, mode_idx + 1, mode->clock, clock);
   3179  1.5.16.1  pgoyette 	mode->clock = clock;
   3180  1.5.16.1  pgoyette }
   3181  1.5.16.1  pgoyette 
   3182       1.1  riastrad static void
   3183       1.1  riastrad parse_hdmi_vsdb(struct drm_connector *connector, const u8 *db)
   3184       1.1  riastrad {
   3185       1.1  riastrad 	u8 len = cea_db_payload_len(db);
   3186       1.1  riastrad 
   3187       1.5  jmcneill 	if (len >= 5) {
   3188       1.5  jmcneill 		connector->physical_address = (db[4] << 8) | db[5];
   3189       1.5  jmcneill 	}
   3190       1.1  riastrad 	if (len >= 6) {
   3191       1.1  riastrad 		connector->eld[5] |= (db[6] >> 7) << 1;  /* Supports_AI */
   3192       1.1  riastrad 		connector->dvi_dual = db[6] & 1;
   3193       1.1  riastrad 	}
   3194       1.1  riastrad 	if (len >= 7)
   3195       1.1  riastrad 		connector->max_tmds_clock = db[7] * 5;
   3196       1.1  riastrad 	if (len >= 8) {
   3197       1.1  riastrad 		connector->latency_present[0] = db[8] >> 7;
   3198       1.1  riastrad 		connector->latency_present[1] = (db[8] >> 6) & 1;
   3199       1.1  riastrad 	}
   3200       1.1  riastrad 	if (len >= 9)
   3201       1.1  riastrad 		connector->video_latency[0] = db[9];
   3202       1.1  riastrad 	if (len >= 10)
   3203       1.1  riastrad 		connector->audio_latency[0] = db[10];
   3204       1.1  riastrad 	if (len >= 11)
   3205       1.1  riastrad 		connector->video_latency[1] = db[11];
   3206       1.1  riastrad 	if (len >= 12)
   3207       1.1  riastrad 		connector->audio_latency[1] = db[12];
   3208       1.1  riastrad 
   3209       1.1  riastrad 	DRM_DEBUG_KMS("HDMI: DVI dual %d, "
   3210       1.1  riastrad 		    "max TMDS clock %d, "
   3211       1.1  riastrad 		    "latency present %d %d, "
   3212       1.1  riastrad 		    "video latency %d %d, "
   3213       1.1  riastrad 		    "audio latency %d %d\n",
   3214       1.1  riastrad 		    connector->dvi_dual,
   3215       1.1  riastrad 		    connector->max_tmds_clock,
   3216       1.1  riastrad 	      (int) connector->latency_present[0],
   3217       1.1  riastrad 	      (int) connector->latency_present[1],
   3218       1.1  riastrad 		    connector->video_latency[0],
   3219       1.1  riastrad 		    connector->video_latency[1],
   3220       1.1  riastrad 		    connector->audio_latency[0],
   3221       1.1  riastrad 		    connector->audio_latency[1]);
   3222       1.1  riastrad }
   3223       1.1  riastrad 
   3224       1.1  riastrad static void
   3225       1.1  riastrad monitor_name(struct detailed_timing *t, void *data)
   3226       1.1  riastrad {
   3227       1.1  riastrad 	if (t->data.other_data.type == EDID_DETAIL_MONITOR_NAME)
   3228       1.1  riastrad 		*(u8 **)data = t->data.other_data.data.str.str;
   3229       1.1  riastrad }
   3230       1.1  riastrad 
   3231       1.1  riastrad /**
   3232       1.1  riastrad  * drm_edid_to_eld - build ELD from EDID
   3233       1.1  riastrad  * @connector: connector corresponding to the HDMI/DP sink
   3234       1.1  riastrad  * @edid: EDID to parse
   3235       1.1  riastrad  *
   3236  1.5.16.1  pgoyette  * Fill the ELD (EDID-Like Data) buffer for passing to the audio driver. The
   3237  1.5.16.1  pgoyette  * HDCP and Port_ID ELD fields are left for the graphics driver to fill in.
   3238       1.1  riastrad  */
   3239       1.1  riastrad void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
   3240       1.1  riastrad {
   3241       1.1  riastrad 	uint8_t *eld = connector->eld;
   3242       1.1  riastrad 	u8 *cea;
   3243       1.1  riastrad 	u8 *name;
   3244       1.1  riastrad 	u8 *db;
   3245       1.1  riastrad 	int sad_count = 0;
   3246       1.1  riastrad 	int mnl;
   3247       1.1  riastrad 	int dbl;
   3248       1.1  riastrad 
   3249       1.1  riastrad 	memset(eld, 0, sizeof(connector->eld));
   3250       1.1  riastrad 
   3251       1.1  riastrad 	cea = drm_find_cea_extension(edid);
   3252       1.1  riastrad 	if (!cea) {
   3253       1.1  riastrad 		DRM_DEBUG_KMS("ELD: no CEA Extension found\n");
   3254       1.1  riastrad 		return;
   3255       1.1  riastrad 	}
   3256       1.1  riastrad 
   3257       1.1  riastrad 	name = NULL;
   3258       1.1  riastrad 	drm_for_each_detailed_block((u8 *)edid, monitor_name, &name);
   3259       1.1  riastrad 	for (mnl = 0; name && mnl < 13; mnl++) {
   3260       1.1  riastrad 		if (name[mnl] == 0x0a)
   3261       1.1  riastrad 			break;
   3262       1.1  riastrad 		eld[20 + mnl] = name[mnl];
   3263       1.1  riastrad 	}
   3264       1.1  riastrad 	eld[4] = (cea[1] << 5) | mnl;
   3265       1.1  riastrad 	DRM_DEBUG_KMS("ELD monitor %s\n", eld + 20);
   3266       1.1  riastrad 
   3267       1.1  riastrad 	eld[0] = 2 << 3;		/* ELD version: 2 */
   3268       1.1  riastrad 
   3269       1.1  riastrad 	eld[16] = edid->mfg_id[0];
   3270       1.1  riastrad 	eld[17] = edid->mfg_id[1];
   3271       1.1  riastrad 	eld[18] = edid->prod_code[0];
   3272       1.1  riastrad 	eld[19] = edid->prod_code[1];
   3273       1.1  riastrad 
   3274       1.1  riastrad 	if (cea_revision(cea) >= 3) {
   3275       1.1  riastrad 		int i, start, end;
   3276       1.1  riastrad 
   3277       1.1  riastrad 		if (cea_db_offsets(cea, &start, &end)) {
   3278       1.1  riastrad 			start = 0;
   3279       1.1  riastrad 			end = 0;
   3280       1.1  riastrad 		}
   3281       1.1  riastrad 
   3282       1.1  riastrad 		for_each_cea_db(cea, i, start, end) {
   3283       1.1  riastrad 			db = &cea[i];
   3284       1.1  riastrad 			dbl = cea_db_payload_len(db);
   3285       1.1  riastrad 
   3286       1.1  riastrad 			switch (cea_db_tag(db)) {
   3287       1.1  riastrad 			case AUDIO_BLOCK:
   3288       1.1  riastrad 				/* Audio Data Block, contains SADs */
   3289       1.1  riastrad 				sad_count = dbl / 3;
   3290       1.1  riastrad 				if (dbl >= 1)
   3291       1.1  riastrad 					memcpy(eld + 20 + mnl, &db[1], dbl);
   3292       1.1  riastrad 				break;
   3293       1.1  riastrad 			case SPEAKER_BLOCK:
   3294       1.1  riastrad 				/* Speaker Allocation Data Block */
   3295       1.1  riastrad 				if (dbl >= 1)
   3296       1.1  riastrad 					eld[7] = db[1];
   3297       1.1  riastrad 				break;
   3298       1.1  riastrad 			case VENDOR_BLOCK:
   3299       1.1  riastrad 				/* HDMI Vendor-Specific Data Block */
   3300       1.1  riastrad 				if (cea_db_is_hdmi_vsdb(db))
   3301       1.1  riastrad 					parse_hdmi_vsdb(connector, db);
   3302       1.1  riastrad 				break;
   3303       1.1  riastrad 			default:
   3304       1.1  riastrad 				break;
   3305       1.1  riastrad 			}
   3306       1.1  riastrad 		}
   3307       1.1  riastrad 	}
   3308       1.1  riastrad 	eld[5] |= sad_count << 4;
   3309       1.1  riastrad 
   3310  1.5.16.1  pgoyette 	if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
   3311  1.5.16.1  pgoyette 	    connector->connector_type == DRM_MODE_CONNECTOR_eDP)
   3312  1.5.16.1  pgoyette 		eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_CONN_TYPE_DP;
   3313  1.5.16.1  pgoyette 	else
   3314  1.5.16.1  pgoyette 		eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_CONN_TYPE_HDMI;
   3315  1.5.16.1  pgoyette 
   3316  1.5.16.1  pgoyette 	eld[DRM_ELD_BASELINE_ELD_LEN] =
   3317  1.5.16.1  pgoyette 		DIV_ROUND_UP(drm_eld_calc_baseline_block_size(eld), 4);
   3318  1.5.16.1  pgoyette 
   3319  1.5.16.1  pgoyette 	DRM_DEBUG_KMS("ELD size %d, SAD count %d\n",
   3320  1.5.16.1  pgoyette 		      drm_eld_size(eld), sad_count);
   3321       1.1  riastrad }
   3322       1.1  riastrad EXPORT_SYMBOL(drm_edid_to_eld);
   3323       1.1  riastrad 
   3324       1.1  riastrad /**
   3325       1.3  riastrad  * drm_edid_to_sad - extracts SADs from EDID
   3326       1.3  riastrad  * @edid: EDID to parse
   3327       1.3  riastrad  * @sads: pointer that will be set to the extracted SADs
   3328       1.3  riastrad  *
   3329       1.3  riastrad  * Looks for CEA EDID block and extracts SADs (Short Audio Descriptors) from it.
   3330       1.3  riastrad  *
   3331  1.5.16.1  pgoyette  * Note: The returned pointer needs to be freed using kfree().
   3332  1.5.16.1  pgoyette  *
   3333  1.5.16.1  pgoyette  * Return: The number of found SADs or negative number on error.
   3334       1.3  riastrad  */
   3335       1.3  riastrad int drm_edid_to_sad(struct edid *edid, struct cea_sad **sads)
   3336       1.3  riastrad {
   3337       1.3  riastrad 	int count = 0;
   3338       1.3  riastrad 	int i, start, end, dbl;
   3339       1.3  riastrad 	u8 *cea;
   3340       1.3  riastrad 
   3341       1.3  riastrad 	cea = drm_find_cea_extension(edid);
   3342       1.3  riastrad 	if (!cea) {
   3343       1.3  riastrad 		DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
   3344       1.3  riastrad 		return -ENOENT;
   3345       1.3  riastrad 	}
   3346       1.3  riastrad 
   3347       1.3  riastrad 	if (cea_revision(cea) < 3) {
   3348       1.3  riastrad 		DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
   3349       1.3  riastrad 		return -ENOTSUPP;
   3350       1.3  riastrad 	}
   3351       1.3  riastrad 
   3352       1.3  riastrad 	if (cea_db_offsets(cea, &start, &end)) {
   3353       1.3  riastrad 		DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
   3354       1.3  riastrad 		return -EPROTO;
   3355       1.3  riastrad 	}
   3356       1.3  riastrad 
   3357       1.3  riastrad 	for_each_cea_db(cea, i, start, end) {
   3358       1.3  riastrad 		u8 *db = &cea[i];
   3359       1.3  riastrad 
   3360       1.3  riastrad 		if (cea_db_tag(db) == AUDIO_BLOCK) {
   3361       1.3  riastrad 			int j;
   3362       1.3  riastrad 			dbl = cea_db_payload_len(db);
   3363       1.3  riastrad 
   3364       1.3  riastrad 			count = dbl / 3; /* SAD is 3B */
   3365       1.3  riastrad 			*sads = kcalloc(count, sizeof(**sads), GFP_KERNEL);
   3366       1.3  riastrad 			if (!*sads)
   3367       1.3  riastrad 				return -ENOMEM;
   3368       1.3  riastrad 			for (j = 0; j < count; j++) {
   3369       1.3  riastrad 				u8 *sad = &db[1 + j * 3];
   3370       1.3  riastrad 
   3371       1.3  riastrad 				(*sads)[j].format = (sad[0] & 0x78) >> 3;
   3372       1.3  riastrad 				(*sads)[j].channels = sad[0] & 0x7;
   3373       1.3  riastrad 				(*sads)[j].freq = sad[1] & 0x7F;
   3374       1.3  riastrad 				(*sads)[j].byte2 = sad[2];
   3375       1.3  riastrad 			}
   3376       1.3  riastrad 			break;
   3377       1.3  riastrad 		}
   3378       1.3  riastrad 	}
   3379       1.3  riastrad 
   3380       1.3  riastrad 	return count;
   3381       1.3  riastrad }
   3382       1.3  riastrad EXPORT_SYMBOL(drm_edid_to_sad);
   3383       1.3  riastrad 
   3384       1.3  riastrad /**
   3385       1.3  riastrad  * drm_edid_to_speaker_allocation - extracts Speaker Allocation Data Blocks from EDID
   3386       1.3  riastrad  * @edid: EDID to parse
   3387       1.3  riastrad  * @sadb: pointer to the speaker block
   3388       1.3  riastrad  *
   3389       1.3  riastrad  * Looks for CEA EDID block and extracts the Speaker Allocation Data Block from it.
   3390       1.3  riastrad  *
   3391  1.5.16.1  pgoyette  * Note: The returned pointer needs to be freed using kfree().
   3392  1.5.16.1  pgoyette  *
   3393  1.5.16.1  pgoyette  * Return: The number of found Speaker Allocation Blocks or negative number on
   3394  1.5.16.1  pgoyette  * error.
   3395       1.3  riastrad  */
   3396       1.3  riastrad int drm_edid_to_speaker_allocation(struct edid *edid, u8 **sadb)
   3397       1.3  riastrad {
   3398       1.3  riastrad 	int count = 0;
   3399       1.3  riastrad 	int i, start, end, dbl;
   3400       1.3  riastrad 	const u8 *cea;
   3401       1.3  riastrad 
   3402       1.3  riastrad 	cea = drm_find_cea_extension(edid);
   3403       1.3  riastrad 	if (!cea) {
   3404       1.3  riastrad 		DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
   3405       1.3  riastrad 		return -ENOENT;
   3406       1.3  riastrad 	}
   3407       1.3  riastrad 
   3408       1.3  riastrad 	if (cea_revision(cea) < 3) {
   3409       1.3  riastrad 		DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
   3410       1.3  riastrad 		return -ENOTSUPP;
   3411       1.3  riastrad 	}
   3412       1.3  riastrad 
   3413       1.3  riastrad 	if (cea_db_offsets(cea, &start, &end)) {
   3414       1.3  riastrad 		DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
   3415       1.3  riastrad 		return -EPROTO;
   3416       1.3  riastrad 	}
   3417       1.3  riastrad 
   3418       1.3  riastrad 	for_each_cea_db(cea, i, start, end) {
   3419       1.3  riastrad 		const u8 *db = &cea[i];
   3420       1.3  riastrad 
   3421       1.3  riastrad 		if (cea_db_tag(db) == SPEAKER_BLOCK) {
   3422       1.3  riastrad 			dbl = cea_db_payload_len(db);
   3423       1.3  riastrad 
   3424       1.3  riastrad 			/* Speaker Allocation Data Block */
   3425       1.3  riastrad 			if (dbl == 3) {
   3426  1.5.16.1  pgoyette 				*sadb = kmemdup(&db[1], dbl, GFP_KERNEL);
   3427       1.3  riastrad 				if (!*sadb)
   3428       1.3  riastrad 					return -ENOMEM;
   3429       1.3  riastrad 				count = dbl;
   3430       1.3  riastrad 				break;
   3431       1.3  riastrad 			}
   3432       1.3  riastrad 		}
   3433       1.3  riastrad 	}
   3434       1.3  riastrad 
   3435       1.3  riastrad 	return count;
   3436       1.3  riastrad }
   3437       1.3  riastrad EXPORT_SYMBOL(drm_edid_to_speaker_allocation);
   3438       1.3  riastrad 
   3439       1.3  riastrad /**
   3440  1.5.16.1  pgoyette  * drm_av_sync_delay - compute the HDMI/DP sink audio-video sync delay
   3441       1.1  riastrad  * @connector: connector associated with the HDMI/DP sink
   3442       1.1  riastrad  * @mode: the display mode
   3443  1.5.16.1  pgoyette  *
   3444  1.5.16.1  pgoyette  * Return: The HDMI/DP sink's audio-video sync delay in milliseconds or 0 if
   3445  1.5.16.1  pgoyette  * the sink doesn't support audio or video.
   3446       1.1  riastrad  */
   3447       1.1  riastrad int drm_av_sync_delay(struct drm_connector *connector,
   3448  1.5.16.1  pgoyette 		      const struct drm_display_mode *mode)
   3449       1.1  riastrad {
   3450       1.1  riastrad 	int i = !!(mode->flags & DRM_MODE_FLAG_INTERLACE);
   3451       1.1  riastrad 	int a, v;
   3452       1.1  riastrad 
   3453       1.1  riastrad 	if (!connector->latency_present[0])
   3454       1.1  riastrad 		return 0;
   3455       1.1  riastrad 	if (!connector->latency_present[1])
   3456       1.1  riastrad 		i = 0;
   3457       1.1  riastrad 
   3458       1.1  riastrad 	a = connector->audio_latency[i];
   3459       1.1  riastrad 	v = connector->video_latency[i];
   3460       1.1  riastrad 
   3461       1.1  riastrad 	/*
   3462       1.1  riastrad 	 * HDMI/DP sink doesn't support audio or video?
   3463       1.1  riastrad 	 */
   3464       1.1  riastrad 	if (a == 255 || v == 255)
   3465       1.1  riastrad 		return 0;
   3466       1.1  riastrad 
   3467       1.1  riastrad 	/*
   3468       1.1  riastrad 	 * Convert raw EDID values to millisecond.
   3469       1.1  riastrad 	 * Treat unknown latency as 0ms.
   3470       1.1  riastrad 	 */
   3471       1.1  riastrad 	if (a)
   3472       1.1  riastrad 		a = min(2 * (a - 1), 500);
   3473       1.1  riastrad 	if (v)
   3474       1.1  riastrad 		v = min(2 * (v - 1), 500);
   3475       1.1  riastrad 
   3476       1.1  riastrad 	return max(v - a, 0);
   3477       1.1  riastrad }
   3478       1.1  riastrad EXPORT_SYMBOL(drm_av_sync_delay);
   3479       1.1  riastrad 
   3480       1.1  riastrad /**
   3481       1.1  riastrad  * drm_select_eld - select one ELD from multiple HDMI/DP sinks
   3482       1.1  riastrad  * @encoder: the encoder just changed display mode
   3483       1.1  riastrad  *
   3484       1.1  riastrad  * It's possible for one encoder to be associated with multiple HDMI/DP sinks.
   3485       1.1  riastrad  * The policy is now hard coded to simply use the first HDMI/DP sink's ELD.
   3486  1.5.16.1  pgoyette  *
   3487  1.5.16.1  pgoyette  * Return: The connector associated with the first HDMI/DP sink that has ELD
   3488  1.5.16.1  pgoyette  * attached to it.
   3489       1.1  riastrad  */
   3490  1.5.16.1  pgoyette struct drm_connector *drm_select_eld(struct drm_encoder *encoder)
   3491       1.1  riastrad {
   3492       1.1  riastrad 	struct drm_connector *connector;
   3493       1.1  riastrad 	struct drm_device *dev = encoder->dev;
   3494       1.1  riastrad 
   3495  1.5.16.1  pgoyette 	WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
   3496  1.5.16.1  pgoyette 	WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
   3497  1.5.16.1  pgoyette 
   3498  1.5.16.1  pgoyette 	drm_for_each_connector(connector, dev)
   3499       1.1  riastrad 		if (connector->encoder == encoder && connector->eld[0])
   3500       1.1  riastrad 			return connector;
   3501       1.1  riastrad 
   3502       1.1  riastrad 	return NULL;
   3503       1.1  riastrad }
   3504       1.1  riastrad EXPORT_SYMBOL(drm_select_eld);
   3505       1.1  riastrad 
   3506       1.1  riastrad /**
   3507  1.5.16.1  pgoyette  * drm_detect_hdmi_monitor - detect whether monitor is HDMI
   3508       1.1  riastrad  * @edid: monitor EDID information
   3509       1.1  riastrad  *
   3510       1.1  riastrad  * Parse the CEA extension according to CEA-861-B.
   3511  1.5.16.1  pgoyette  *
   3512  1.5.16.1  pgoyette  * Return: True if the monitor is HDMI, false if not or unknown.
   3513       1.1  riastrad  */
   3514       1.1  riastrad bool drm_detect_hdmi_monitor(struct edid *edid)
   3515       1.1  riastrad {
   3516       1.1  riastrad 	u8 *edid_ext;
   3517       1.1  riastrad 	int i;
   3518       1.1  riastrad 	int start_offset, end_offset;
   3519       1.1  riastrad 
   3520       1.1  riastrad 	edid_ext = drm_find_cea_extension(edid);
   3521       1.1  riastrad 	if (!edid_ext)
   3522       1.1  riastrad 		return false;
   3523       1.1  riastrad 
   3524       1.1  riastrad 	if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
   3525       1.1  riastrad 		return false;
   3526       1.1  riastrad 
   3527       1.1  riastrad 	/*
   3528       1.1  riastrad 	 * Because HDMI identifier is in Vendor Specific Block,
   3529       1.1  riastrad 	 * search it from all data blocks of CEA extension.
   3530       1.1  riastrad 	 */
   3531       1.1  riastrad 	for_each_cea_db(edid_ext, i, start_offset, end_offset) {
   3532       1.1  riastrad 		if (cea_db_is_hdmi_vsdb(&edid_ext[i]))
   3533       1.1  riastrad 			return true;
   3534       1.1  riastrad 	}
   3535       1.1  riastrad 
   3536       1.1  riastrad 	return false;
   3537       1.1  riastrad }
   3538       1.1  riastrad EXPORT_SYMBOL(drm_detect_hdmi_monitor);
   3539       1.1  riastrad 
   3540       1.1  riastrad /**
   3541       1.1  riastrad  * drm_detect_monitor_audio - check monitor audio capability
   3542       1.3  riastrad  * @edid: EDID block to scan
   3543       1.1  riastrad  *
   3544       1.1  riastrad  * Monitor should have CEA extension block.
   3545       1.1  riastrad  * If monitor has 'basic audio', but no CEA audio blocks, it's 'basic
   3546       1.1  riastrad  * audio' only. If there is any audio extension block and supported
   3547       1.1  riastrad  * audio format, assume at least 'basic audio' support, even if 'basic
   3548       1.1  riastrad  * audio' is not defined in EDID.
   3549       1.1  riastrad  *
   3550  1.5.16.1  pgoyette  * Return: True if the monitor supports audio, false otherwise.
   3551       1.1  riastrad  */
   3552       1.1  riastrad bool drm_detect_monitor_audio(struct edid *edid)
   3553       1.1  riastrad {
   3554       1.1  riastrad 	u8 *edid_ext;
   3555       1.1  riastrad 	int i, j;
   3556       1.1  riastrad 	bool has_audio = false;
   3557       1.1  riastrad 	int start_offset, end_offset;
   3558       1.1  riastrad 
   3559       1.1  riastrad 	edid_ext = drm_find_cea_extension(edid);
   3560       1.1  riastrad 	if (!edid_ext)
   3561       1.1  riastrad 		goto end;
   3562       1.1  riastrad 
   3563       1.1  riastrad 	has_audio = ((edid_ext[3] & EDID_BASIC_AUDIO) != 0);
   3564       1.1  riastrad 
   3565       1.1  riastrad 	if (has_audio) {
   3566       1.1  riastrad 		DRM_DEBUG_KMS("Monitor has basic audio support\n");
   3567       1.1  riastrad 		goto end;
   3568       1.1  riastrad 	}
   3569       1.1  riastrad 
   3570       1.1  riastrad 	if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
   3571       1.1  riastrad 		goto end;
   3572       1.1  riastrad 
   3573       1.1  riastrad 	for_each_cea_db(edid_ext, i, start_offset, end_offset) {
   3574       1.1  riastrad 		if (cea_db_tag(&edid_ext[i]) == AUDIO_BLOCK) {
   3575       1.1  riastrad 			has_audio = true;
   3576       1.1  riastrad 			for (j = 1; j < cea_db_payload_len(&edid_ext[i]) + 1; j += 3)
   3577       1.1  riastrad 				DRM_DEBUG_KMS("CEA audio format %d\n",
   3578       1.1  riastrad 					      (edid_ext[i + j] >> 3) & 0xf);
   3579       1.1  riastrad 			goto end;
   3580       1.1  riastrad 		}
   3581       1.1  riastrad 	}
   3582       1.1  riastrad end:
   3583       1.1  riastrad 	return has_audio;
   3584       1.1  riastrad }
   3585       1.1  riastrad EXPORT_SYMBOL(drm_detect_monitor_audio);
   3586       1.1  riastrad 
   3587       1.1  riastrad /**
   3588       1.3  riastrad  * drm_rgb_quant_range_selectable - is RGB quantization range selectable?
   3589       1.3  riastrad  * @edid: EDID block to scan
   3590       1.3  riastrad  *
   3591       1.3  riastrad  * Check whether the monitor reports the RGB quantization range selection
   3592       1.3  riastrad  * as supported. The AVI infoframe can then be used to inform the monitor
   3593       1.3  riastrad  * which quantization range (full or limited) is used.
   3594  1.5.16.1  pgoyette  *
   3595  1.5.16.1  pgoyette  * Return: True if the RGB quantization range is selectable, false otherwise.
   3596       1.3  riastrad  */
   3597       1.3  riastrad bool drm_rgb_quant_range_selectable(struct edid *edid)
   3598       1.3  riastrad {
   3599       1.3  riastrad 	u8 *edid_ext;
   3600       1.3  riastrad 	int i, start, end;
   3601       1.3  riastrad 
   3602       1.3  riastrad 	edid_ext = drm_find_cea_extension(edid);
   3603       1.3  riastrad 	if (!edid_ext)
   3604       1.3  riastrad 		return false;
   3605       1.3  riastrad 
   3606       1.3  riastrad 	if (cea_db_offsets(edid_ext, &start, &end))
   3607       1.3  riastrad 		return false;
   3608       1.3  riastrad 
   3609       1.3  riastrad 	for_each_cea_db(edid_ext, i, start, end) {
   3610       1.3  riastrad 		if (cea_db_tag(&edid_ext[i]) == VIDEO_CAPABILITY_BLOCK &&
   3611       1.3  riastrad 		    cea_db_payload_len(&edid_ext[i]) == 2) {
   3612       1.3  riastrad 			DRM_DEBUG_KMS("CEA VCDB 0x%02x\n", edid_ext[i + 2]);
   3613       1.3  riastrad 			return edid_ext[i + 2] & EDID_CEA_VCDB_QS;
   3614       1.3  riastrad 		}
   3615       1.3  riastrad 	}
   3616       1.3  riastrad 
   3617       1.3  riastrad 	return false;
   3618       1.3  riastrad }
   3619       1.3  riastrad EXPORT_SYMBOL(drm_rgb_quant_range_selectable);
   3620       1.3  riastrad 
   3621       1.3  riastrad /**
   3622  1.5.16.1  pgoyette  * drm_assign_hdmi_deep_color_info - detect whether monitor supports
   3623  1.5.16.1  pgoyette  * hdmi deep color modes and update drm_display_info if so.
   3624  1.5.16.1  pgoyette  * @edid: monitor EDID information
   3625  1.5.16.1  pgoyette  * @info: Updated with maximum supported deep color bpc and color format
   3626  1.5.16.1  pgoyette  *        if deep color supported.
   3627  1.5.16.1  pgoyette  * @connector: DRM connector, used only for debug output
   3628  1.5.16.1  pgoyette  *
   3629  1.5.16.1  pgoyette  * Parse the CEA extension according to CEA-861-B.
   3630  1.5.16.1  pgoyette  * Return true if HDMI deep color supported, false if not or unknown.
   3631  1.5.16.1  pgoyette  */
   3632  1.5.16.1  pgoyette static bool drm_assign_hdmi_deep_color_info(struct edid *edid,
   3633  1.5.16.1  pgoyette                                             struct drm_display_info *info,
   3634  1.5.16.1  pgoyette                                             struct drm_connector *connector)
   3635  1.5.16.1  pgoyette {
   3636  1.5.16.1  pgoyette 	u8 *edid_ext, *hdmi;
   3637  1.5.16.1  pgoyette 	int i;
   3638  1.5.16.1  pgoyette 	int start_offset, end_offset;
   3639  1.5.16.1  pgoyette 	unsigned int dc_bpc = 0;
   3640  1.5.16.1  pgoyette 
   3641  1.5.16.1  pgoyette 	edid_ext = drm_find_cea_extension(edid);
   3642  1.5.16.1  pgoyette 	if (!edid_ext)
   3643  1.5.16.1  pgoyette 		return false;
   3644  1.5.16.1  pgoyette 
   3645  1.5.16.1  pgoyette 	if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
   3646  1.5.16.1  pgoyette 		return false;
   3647  1.5.16.1  pgoyette 
   3648  1.5.16.1  pgoyette 	/*
   3649  1.5.16.1  pgoyette 	 * Because HDMI identifier is in Vendor Specific Block,
   3650  1.5.16.1  pgoyette 	 * search it from all data blocks of CEA extension.
   3651  1.5.16.1  pgoyette 	 */
   3652  1.5.16.1  pgoyette 	for_each_cea_db(edid_ext, i, start_offset, end_offset) {
   3653  1.5.16.1  pgoyette 		if (cea_db_is_hdmi_vsdb(&edid_ext[i])) {
   3654  1.5.16.1  pgoyette 			/* HDMI supports at least 8 bpc */
   3655  1.5.16.1  pgoyette 			info->bpc = 8;
   3656  1.5.16.1  pgoyette 
   3657  1.5.16.1  pgoyette 			hdmi = &edid_ext[i];
   3658  1.5.16.1  pgoyette 			if (cea_db_payload_len(hdmi) < 6)
   3659  1.5.16.1  pgoyette 				return false;
   3660  1.5.16.1  pgoyette 
   3661  1.5.16.1  pgoyette 			if (hdmi[6] & DRM_EDID_HDMI_DC_30) {
   3662  1.5.16.1  pgoyette 				dc_bpc = 10;
   3663  1.5.16.1  pgoyette 				info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_30;
   3664  1.5.16.1  pgoyette 				DRM_DEBUG("%s: HDMI sink does deep color 30.\n",
   3665  1.5.16.1  pgoyette 						  connector->name);
   3666  1.5.16.1  pgoyette 			}
   3667  1.5.16.1  pgoyette 
   3668  1.5.16.1  pgoyette 			if (hdmi[6] & DRM_EDID_HDMI_DC_36) {
   3669  1.5.16.1  pgoyette 				dc_bpc = 12;
   3670  1.5.16.1  pgoyette 				info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_36;
   3671  1.5.16.1  pgoyette 				DRM_DEBUG("%s: HDMI sink does deep color 36.\n",
   3672  1.5.16.1  pgoyette 						  connector->name);
   3673  1.5.16.1  pgoyette 			}
   3674  1.5.16.1  pgoyette 
   3675  1.5.16.1  pgoyette 			if (hdmi[6] & DRM_EDID_HDMI_DC_48) {
   3676  1.5.16.1  pgoyette 				dc_bpc = 16;
   3677  1.5.16.1  pgoyette 				info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_48;
   3678  1.5.16.1  pgoyette 				DRM_DEBUG("%s: HDMI sink does deep color 48.\n",
   3679  1.5.16.1  pgoyette 						  connector->name);
   3680  1.5.16.1  pgoyette 			}
   3681  1.5.16.1  pgoyette 
   3682  1.5.16.1  pgoyette 			if (dc_bpc > 0) {
   3683  1.5.16.1  pgoyette 				DRM_DEBUG("%s: Assigning HDMI sink color depth as %d bpc.\n",
   3684  1.5.16.1  pgoyette 						  connector->name, dc_bpc);
   3685  1.5.16.1  pgoyette 				info->bpc = dc_bpc;
   3686  1.5.16.1  pgoyette 
   3687  1.5.16.1  pgoyette 				/*
   3688  1.5.16.1  pgoyette 				 * Deep color support mandates RGB444 support for all video
   3689  1.5.16.1  pgoyette 				 * modes and forbids YCRCB422 support for all video modes per
   3690  1.5.16.1  pgoyette 				 * HDMI 1.3 spec.
   3691  1.5.16.1  pgoyette 				 */
   3692  1.5.16.1  pgoyette 				info->color_formats = DRM_COLOR_FORMAT_RGB444;
   3693  1.5.16.1  pgoyette 
   3694  1.5.16.1  pgoyette 				/* YCRCB444 is optional according to spec. */
   3695  1.5.16.1  pgoyette 				if (hdmi[6] & DRM_EDID_HDMI_DC_Y444) {
   3696  1.5.16.1  pgoyette 					info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
   3697  1.5.16.1  pgoyette 					DRM_DEBUG("%s: HDMI sink does YCRCB444 in deep color.\n",
   3698  1.5.16.1  pgoyette 							  connector->name);
   3699  1.5.16.1  pgoyette 				}
   3700  1.5.16.1  pgoyette 
   3701  1.5.16.1  pgoyette 				/*
   3702  1.5.16.1  pgoyette 				 * Spec says that if any deep color mode is supported at all,
   3703  1.5.16.1  pgoyette 				 * then deep color 36 bit must be supported.
   3704  1.5.16.1  pgoyette 				 */
   3705  1.5.16.1  pgoyette 				if (!(hdmi[6] & DRM_EDID_HDMI_DC_36)) {
   3706  1.5.16.1  pgoyette 					DRM_DEBUG("%s: HDMI sink should do DC_36, but does not!\n",
   3707  1.5.16.1  pgoyette 							  connector->name);
   3708  1.5.16.1  pgoyette 				}
   3709  1.5.16.1  pgoyette 
   3710  1.5.16.1  pgoyette 				return true;
   3711  1.5.16.1  pgoyette 			}
   3712  1.5.16.1  pgoyette 			else {
   3713  1.5.16.1  pgoyette 				DRM_DEBUG("%s: No deep color support on this HDMI sink.\n",
   3714  1.5.16.1  pgoyette 						  connector->name);
   3715  1.5.16.1  pgoyette 			}
   3716  1.5.16.1  pgoyette 		}
   3717  1.5.16.1  pgoyette 	}
   3718  1.5.16.1  pgoyette 
   3719  1.5.16.1  pgoyette 	return false;
   3720  1.5.16.1  pgoyette }
   3721  1.5.16.1  pgoyette 
   3722  1.5.16.1  pgoyette /**
   3723       1.1  riastrad  * drm_add_display_info - pull display info out if present
   3724       1.1  riastrad  * @edid: EDID data
   3725       1.1  riastrad  * @info: display info (attached to connector)
   3726  1.5.16.1  pgoyette  * @connector: connector whose edid is used to build display info
   3727       1.1  riastrad  *
   3728       1.1  riastrad  * Grab any available display info and stuff it into the drm_display_info
   3729       1.1  riastrad  * structure that's part of the connector.  Useful for tracking bpp and
   3730       1.1  riastrad  * color spaces.
   3731       1.1  riastrad  */
   3732       1.1  riastrad static void drm_add_display_info(struct edid *edid,
   3733  1.5.16.1  pgoyette                                  struct drm_display_info *info,
   3734  1.5.16.1  pgoyette                                  struct drm_connector *connector)
   3735       1.1  riastrad {
   3736       1.1  riastrad 	u8 *edid_ext;
   3737       1.1  riastrad 
   3738       1.1  riastrad 	info->width_mm = edid->width_cm * 10;
   3739       1.1  riastrad 	info->height_mm = edid->height_cm * 10;
   3740       1.1  riastrad 
   3741       1.1  riastrad 	/* driver figures it out in this case */
   3742       1.1  riastrad 	info->bpc = 0;
   3743       1.1  riastrad 	info->color_formats = 0;
   3744       1.1  riastrad 
   3745       1.1  riastrad 	if (edid->revision < 3)
   3746       1.1  riastrad 		return;
   3747       1.1  riastrad 
   3748       1.1  riastrad 	if (!(edid->input & DRM_EDID_INPUT_DIGITAL))
   3749       1.1  riastrad 		return;
   3750       1.1  riastrad 
   3751       1.1  riastrad 	/* Get data from CEA blocks if present */
   3752       1.1  riastrad 	edid_ext = drm_find_cea_extension(edid);
   3753       1.1  riastrad 	if (edid_ext) {
   3754       1.1  riastrad 		info->cea_rev = edid_ext[1];
   3755       1.1  riastrad 
   3756       1.1  riastrad 		/* The existence of a CEA block should imply RGB support */
   3757       1.1  riastrad 		info->color_formats = DRM_COLOR_FORMAT_RGB444;
   3758       1.1  riastrad 		if (edid_ext[3] & EDID_CEA_YCRCB444)
   3759       1.1  riastrad 			info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
   3760       1.1  riastrad 		if (edid_ext[3] & EDID_CEA_YCRCB422)
   3761       1.1  riastrad 			info->color_formats |= DRM_COLOR_FORMAT_YCRCB422;
   3762       1.1  riastrad 	}
   3763       1.1  riastrad 
   3764  1.5.16.1  pgoyette 	/* HDMI deep color modes supported? Assign to info, if so */
   3765  1.5.16.1  pgoyette 	drm_assign_hdmi_deep_color_info(edid, info, connector);
   3766  1.5.16.1  pgoyette 
   3767       1.1  riastrad 	/* Only defined for 1.4 with digital displays */
   3768       1.1  riastrad 	if (edid->revision < 4)
   3769       1.1  riastrad 		return;
   3770       1.1  riastrad 
   3771       1.1  riastrad 	switch (edid->input & DRM_EDID_DIGITAL_DEPTH_MASK) {
   3772       1.1  riastrad 	case DRM_EDID_DIGITAL_DEPTH_6:
   3773       1.1  riastrad 		info->bpc = 6;
   3774       1.1  riastrad 		break;
   3775       1.1  riastrad 	case DRM_EDID_DIGITAL_DEPTH_8:
   3776       1.1  riastrad 		info->bpc = 8;
   3777       1.1  riastrad 		break;
   3778       1.1  riastrad 	case DRM_EDID_DIGITAL_DEPTH_10:
   3779       1.1  riastrad 		info->bpc = 10;
   3780       1.1  riastrad 		break;
   3781       1.1  riastrad 	case DRM_EDID_DIGITAL_DEPTH_12:
   3782       1.1  riastrad 		info->bpc = 12;
   3783       1.1  riastrad 		break;
   3784       1.1  riastrad 	case DRM_EDID_DIGITAL_DEPTH_14:
   3785       1.1  riastrad 		info->bpc = 14;
   3786       1.1  riastrad 		break;
   3787       1.1  riastrad 	case DRM_EDID_DIGITAL_DEPTH_16:
   3788       1.1  riastrad 		info->bpc = 16;
   3789       1.1  riastrad 		break;
   3790       1.1  riastrad 	case DRM_EDID_DIGITAL_DEPTH_UNDEF:
   3791       1.1  riastrad 	default:
   3792       1.1  riastrad 		info->bpc = 0;
   3793       1.1  riastrad 		break;
   3794       1.1  riastrad 	}
   3795       1.1  riastrad 
   3796  1.5.16.1  pgoyette 	DRM_DEBUG("%s: Assigning EDID-1.4 digital sink color depth as %d bpc.\n",
   3797  1.5.16.1  pgoyette 			  connector->name, info->bpc);
   3798  1.5.16.1  pgoyette 
   3799       1.1  riastrad 	info->color_formats |= DRM_COLOR_FORMAT_RGB444;
   3800       1.1  riastrad 	if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB444)
   3801       1.1  riastrad 		info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
   3802       1.1  riastrad 	if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB422)
   3803       1.1  riastrad 		info->color_formats |= DRM_COLOR_FORMAT_YCRCB422;
   3804       1.1  riastrad }
   3805       1.1  riastrad 
   3806       1.1  riastrad /**
   3807       1.1  riastrad  * drm_add_edid_modes - add modes from EDID data, if available
   3808       1.1  riastrad  * @connector: connector we're probing
   3809  1.5.16.1  pgoyette  * @edid: EDID data
   3810       1.1  riastrad  *
   3811       1.1  riastrad  * Add the specified modes to the connector's mode list.
   3812       1.1  riastrad  *
   3813  1.5.16.1  pgoyette  * Return: The number of modes added or 0 if we couldn't find any.
   3814       1.1  riastrad  */
   3815       1.1  riastrad int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid)
   3816       1.1  riastrad {
   3817       1.1  riastrad 	int num_modes = 0;
   3818       1.1  riastrad 	u32 quirks;
   3819       1.1  riastrad 
   3820       1.1  riastrad 	if (edid == NULL) {
   3821       1.1  riastrad 		return 0;
   3822       1.1  riastrad 	}
   3823       1.1  riastrad 	if (!drm_edid_is_valid(edid)) {
   3824       1.1  riastrad 		dev_warn(connector->dev->dev, "%s: EDID invalid.\n",
   3825  1.5.16.1  pgoyette 			 connector->name);
   3826       1.1  riastrad 		return 0;
   3827       1.1  riastrad 	}
   3828       1.1  riastrad 
   3829       1.1  riastrad 	quirks = edid_get_quirks(edid);
   3830       1.1  riastrad 
   3831       1.1  riastrad 	/*
   3832       1.1  riastrad 	 * EDID spec says modes should be preferred in this order:
   3833       1.1  riastrad 	 * - preferred detailed mode
   3834       1.1  riastrad 	 * - other detailed modes from base block
   3835       1.1  riastrad 	 * - detailed modes from extension blocks
   3836       1.1  riastrad 	 * - CVT 3-byte code modes
   3837       1.1  riastrad 	 * - standard timing codes
   3838       1.1  riastrad 	 * - established timing codes
   3839       1.1  riastrad 	 * - modes inferred from GTF or CVT range information
   3840       1.1  riastrad 	 *
   3841       1.1  riastrad 	 * We get this pretty much right.
   3842       1.1  riastrad 	 *
   3843       1.1  riastrad 	 * XXX order for additional mode types in extension blocks?
   3844       1.1  riastrad 	 */
   3845       1.1  riastrad 	num_modes += add_detailed_modes(connector, edid, quirks);
   3846       1.1  riastrad 	num_modes += add_cvt_modes(connector, edid);
   3847       1.1  riastrad 	num_modes += add_standard_modes(connector, edid);
   3848       1.1  riastrad 	num_modes += add_established_modes(connector, edid);
   3849       1.1  riastrad 	num_modes += add_cea_modes(connector, edid);
   3850       1.3  riastrad 	num_modes += add_alternate_cea_modes(connector, edid);
   3851  1.5.16.1  pgoyette 	if (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF)
   3852  1.5.16.1  pgoyette 		num_modes += add_inferred_modes(connector, edid);
   3853       1.1  riastrad 
   3854       1.1  riastrad 	if (quirks & (EDID_QUIRK_PREFER_LARGE_60 | EDID_QUIRK_PREFER_LARGE_75))
   3855       1.1  riastrad 		edid_fixup_preferred(connector, quirks);
   3856       1.1  riastrad 
   3857  1.5.16.1  pgoyette 	drm_add_display_info(edid, &connector->display_info, connector);
   3858  1.5.16.1  pgoyette 
   3859  1.5.16.1  pgoyette 	if (quirks & EDID_QUIRK_FORCE_6BPC)
   3860  1.5.16.1  pgoyette 		connector->display_info.bpc = 6;
   3861       1.1  riastrad 
   3862       1.3  riastrad 	if (quirks & EDID_QUIRK_FORCE_8BPC)
   3863       1.3  riastrad 		connector->display_info.bpc = 8;
   3864       1.3  riastrad 
   3865  1.5.16.1  pgoyette 	if (quirks & EDID_QUIRK_FORCE_10BPC)
   3866  1.5.16.1  pgoyette 		connector->display_info.bpc = 10;
   3867  1.5.16.1  pgoyette 
   3868  1.5.16.1  pgoyette 	if (quirks & EDID_QUIRK_FORCE_12BPC)
   3869  1.5.16.1  pgoyette 		connector->display_info.bpc = 12;
   3870  1.5.16.1  pgoyette 
   3871       1.1  riastrad 	return num_modes;
   3872       1.1  riastrad }
   3873       1.1  riastrad EXPORT_SYMBOL(drm_add_edid_modes);
   3874       1.1  riastrad 
   3875       1.1  riastrad /**
   3876       1.1  riastrad  * drm_add_modes_noedid - add modes for the connectors without EDID
   3877       1.1  riastrad  * @connector: connector we're probing
   3878       1.1  riastrad  * @hdisplay: the horizontal display limit
   3879       1.1  riastrad  * @vdisplay: the vertical display limit
   3880       1.1  riastrad  *
   3881       1.1  riastrad  * Add the specified modes to the connector's mode list. Only when the
   3882       1.1  riastrad  * hdisplay/vdisplay is not beyond the given limit, it will be added.
   3883       1.1  riastrad  *
   3884  1.5.16.1  pgoyette  * Return: The number of modes added or 0 if we couldn't find any.
   3885       1.1  riastrad  */
   3886       1.1  riastrad int drm_add_modes_noedid(struct drm_connector *connector,
   3887       1.1  riastrad 			int hdisplay, int vdisplay)
   3888       1.1  riastrad {
   3889       1.1  riastrad 	int i, count, num_modes = 0;
   3890       1.1  riastrad 	struct drm_display_mode *mode;
   3891       1.1  riastrad 	struct drm_device *dev = connector->dev;
   3892       1.1  riastrad 
   3893  1.5.16.1  pgoyette 	count = ARRAY_SIZE(drm_dmt_modes);
   3894       1.1  riastrad 	if (hdisplay < 0)
   3895       1.1  riastrad 		hdisplay = 0;
   3896       1.1  riastrad 	if (vdisplay < 0)
   3897       1.1  riastrad 		vdisplay = 0;
   3898       1.1  riastrad 
   3899       1.1  riastrad 	for (i = 0; i < count; i++) {
   3900       1.1  riastrad 		const struct drm_display_mode *ptr = &drm_dmt_modes[i];
   3901       1.1  riastrad 		if (hdisplay && vdisplay) {
   3902       1.1  riastrad 			/*
   3903       1.1  riastrad 			 * Only when two are valid, they will be used to check
   3904       1.1  riastrad 			 * whether the mode should be added to the mode list of
   3905       1.1  riastrad 			 * the connector.
   3906       1.1  riastrad 			 */
   3907       1.1  riastrad 			if (ptr->hdisplay > hdisplay ||
   3908       1.1  riastrad 					ptr->vdisplay > vdisplay)
   3909       1.1  riastrad 				continue;
   3910       1.1  riastrad 		}
   3911       1.1  riastrad 		if (drm_mode_vrefresh(ptr) > 61)
   3912       1.1  riastrad 			continue;
   3913       1.1  riastrad 		mode = drm_mode_duplicate(dev, ptr);
   3914       1.1  riastrad 		if (mode) {
   3915       1.1  riastrad 			drm_mode_probed_add(connector, mode);
   3916       1.1  riastrad 			num_modes++;
   3917       1.1  riastrad 		}
   3918       1.1  riastrad 	}
   3919       1.1  riastrad 	return num_modes;
   3920       1.1  riastrad }
   3921       1.1  riastrad EXPORT_SYMBOL(drm_add_modes_noedid);
   3922       1.1  riastrad 
   3923  1.5.16.1  pgoyette /**
   3924  1.5.16.1  pgoyette  * drm_set_preferred_mode - Sets the preferred mode of a connector
   3925  1.5.16.1  pgoyette  * @connector: connector whose mode list should be processed
   3926  1.5.16.1  pgoyette  * @hpref: horizontal resolution of preferred mode
   3927  1.5.16.1  pgoyette  * @vpref: vertical resolution of preferred mode
   3928  1.5.16.1  pgoyette  *
   3929  1.5.16.1  pgoyette  * Marks a mode as preferred if it matches the resolution specified by @hpref
   3930  1.5.16.1  pgoyette  * and @vpref.
   3931  1.5.16.1  pgoyette  */
   3932       1.3  riastrad void drm_set_preferred_mode(struct drm_connector *connector,
   3933       1.3  riastrad 			   int hpref, int vpref)
   3934       1.3  riastrad {
   3935       1.3  riastrad 	struct drm_display_mode *mode;
   3936       1.3  riastrad 
   3937       1.3  riastrad 	list_for_each_entry(mode, &connector->probed_modes, head) {
   3938  1.5.16.1  pgoyette 		if (mode->hdisplay == hpref &&
   3939       1.3  riastrad 		    mode->vdisplay == vpref)
   3940       1.3  riastrad 			mode->type |= DRM_MODE_TYPE_PREFERRED;
   3941       1.3  riastrad 	}
   3942       1.3  riastrad }
   3943       1.3  riastrad EXPORT_SYMBOL(drm_set_preferred_mode);
   3944       1.3  riastrad 
   3945       1.1  riastrad /**
   3946       1.3  riastrad  * drm_hdmi_avi_infoframe_from_display_mode() - fill an HDMI AVI infoframe with
   3947       1.3  riastrad  *                                              data from a DRM display mode
   3948       1.3  riastrad  * @frame: HDMI AVI infoframe
   3949       1.3  riastrad  * @mode: DRM display mode
   3950       1.1  riastrad  *
   3951  1.5.16.1  pgoyette  * Return: 0 on success or a negative error code on failure.
   3952       1.1  riastrad  */
   3953       1.3  riastrad int
   3954       1.3  riastrad drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
   3955       1.3  riastrad 					 const struct drm_display_mode *mode)
   3956       1.1  riastrad {
   3957       1.3  riastrad 	int err;
   3958       1.3  riastrad 
   3959       1.3  riastrad 	if (!frame || !mode)
   3960       1.3  riastrad 		return -EINVAL;
   3961       1.3  riastrad 
   3962       1.3  riastrad 	err = hdmi_avi_infoframe_init(frame);
   3963       1.3  riastrad 	if (err < 0)
   3964       1.3  riastrad 		return err;
   3965       1.3  riastrad 
   3966       1.3  riastrad 	if (mode->flags & DRM_MODE_FLAG_DBLCLK)
   3967       1.3  riastrad 		frame->pixel_repeat = 1;
   3968       1.1  riastrad 
   3969       1.3  riastrad 	frame->video_code = drm_match_cea_mode(mode);
   3970       1.3  riastrad 
   3971       1.3  riastrad 	frame->picture_aspect = HDMI_PICTURE_ASPECT_NONE;
   3972  1.5.16.1  pgoyette 
   3973  1.5.16.1  pgoyette 	/*
   3974  1.5.16.1  pgoyette 	 * Populate picture aspect ratio from either
   3975  1.5.16.1  pgoyette 	 * user input (if specified) or from the CEA mode list.
   3976  1.5.16.1  pgoyette 	 */
   3977  1.5.16.1  pgoyette 	if (mode->picture_aspect_ratio == HDMI_PICTURE_ASPECT_4_3 ||
   3978  1.5.16.1  pgoyette 		mode->picture_aspect_ratio == HDMI_PICTURE_ASPECT_16_9)
   3979  1.5.16.1  pgoyette 		frame->picture_aspect = mode->picture_aspect_ratio;
   3980  1.5.16.1  pgoyette 	else if (frame->video_code > 0)
   3981  1.5.16.1  pgoyette 		frame->picture_aspect = drm_get_cea_aspect_ratio(
   3982  1.5.16.1  pgoyette 						frame->video_code);
   3983  1.5.16.1  pgoyette 
   3984       1.3  riastrad 	frame->active_aspect = HDMI_ACTIVE_ASPECT_PICTURE;
   3985       1.3  riastrad 	frame->scan_mode = HDMI_SCAN_MODE_UNDERSCAN;
   3986       1.3  riastrad 
   3987       1.3  riastrad 	return 0;
   3988       1.3  riastrad }
   3989       1.3  riastrad EXPORT_SYMBOL(drm_hdmi_avi_infoframe_from_display_mode);
   3990       1.3  riastrad 
   3991       1.3  riastrad static enum hdmi_3d_structure
   3992       1.3  riastrad s3d_structure_from_display_mode(const struct drm_display_mode *mode)
   3993       1.3  riastrad {
   3994       1.3  riastrad 	u32 layout = mode->flags & DRM_MODE_FLAG_3D_MASK;
   3995       1.3  riastrad 
   3996       1.3  riastrad 	switch (layout) {
   3997       1.3  riastrad 	case DRM_MODE_FLAG_3D_FRAME_PACKING:
   3998       1.3  riastrad 		return HDMI_3D_STRUCTURE_FRAME_PACKING;
   3999       1.3  riastrad 	case DRM_MODE_FLAG_3D_FIELD_ALTERNATIVE:
   4000       1.3  riastrad 		return HDMI_3D_STRUCTURE_FIELD_ALTERNATIVE;
   4001       1.3  riastrad 	case DRM_MODE_FLAG_3D_LINE_ALTERNATIVE:
   4002       1.3  riastrad 		return HDMI_3D_STRUCTURE_LINE_ALTERNATIVE;
   4003       1.3  riastrad 	case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_FULL:
   4004       1.3  riastrad 		return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_FULL;
   4005       1.3  riastrad 	case DRM_MODE_FLAG_3D_L_DEPTH:
   4006       1.3  riastrad 		return HDMI_3D_STRUCTURE_L_DEPTH;
   4007       1.3  riastrad 	case DRM_MODE_FLAG_3D_L_DEPTH_GFX_GFX_DEPTH:
   4008       1.3  riastrad 		return HDMI_3D_STRUCTURE_L_DEPTH_GFX_GFX_DEPTH;
   4009       1.3  riastrad 	case DRM_MODE_FLAG_3D_TOP_AND_BOTTOM:
   4010       1.3  riastrad 		return HDMI_3D_STRUCTURE_TOP_AND_BOTTOM;
   4011       1.3  riastrad 	case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF:
   4012       1.3  riastrad 		return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF;
   4013       1.3  riastrad 	default:
   4014       1.3  riastrad 		return HDMI_3D_STRUCTURE_INVALID;
   4015       1.3  riastrad 	}
   4016       1.3  riastrad }
   4017       1.3  riastrad 
   4018       1.3  riastrad /**
   4019       1.3  riastrad  * drm_hdmi_vendor_infoframe_from_display_mode() - fill an HDMI infoframe with
   4020       1.3  riastrad  * data from a DRM display mode
   4021       1.3  riastrad  * @frame: HDMI vendor infoframe
   4022       1.3  riastrad  * @mode: DRM display mode
   4023       1.3  riastrad  *
   4024       1.3  riastrad  * Note that there's is a need to send HDMI vendor infoframes only when using a
   4025       1.3  riastrad  * 4k or stereoscopic 3D mode. So when giving any other mode as input this
   4026       1.3  riastrad  * function will return -EINVAL, error that can be safely ignored.
   4027       1.3  riastrad  *
   4028  1.5.16.1  pgoyette  * Return: 0 on success or a negative error code on failure.
   4029       1.3  riastrad  */
   4030       1.3  riastrad int
   4031       1.3  riastrad drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
   4032       1.3  riastrad 					    const struct drm_display_mode *mode)
   4033       1.3  riastrad {
   4034       1.3  riastrad 	int err;
   4035       1.3  riastrad 	u32 s3d_flags;
   4036       1.3  riastrad 	u8 vic;
   4037       1.3  riastrad 
   4038       1.3  riastrad 	if (!frame || !mode)
   4039       1.3  riastrad 		return -EINVAL;
   4040       1.3  riastrad 
   4041       1.3  riastrad 	vic = drm_match_hdmi_mode(mode);
   4042       1.3  riastrad 	s3d_flags = mode->flags & DRM_MODE_FLAG_3D_MASK;
   4043       1.3  riastrad 
   4044       1.3  riastrad 	if (!vic && !s3d_flags)
   4045       1.3  riastrad 		return -EINVAL;
   4046       1.3  riastrad 
   4047       1.3  riastrad 	if (vic && s3d_flags)
   4048       1.3  riastrad 		return -EINVAL;
   4049       1.3  riastrad 
   4050       1.3  riastrad 	err = hdmi_vendor_infoframe_init(frame);
   4051       1.3  riastrad 	if (err < 0)
   4052       1.3  riastrad 		return err;
   4053       1.3  riastrad 
   4054       1.3  riastrad 	if (vic)
   4055       1.3  riastrad 		frame->vic = vic;
   4056       1.3  riastrad 	else
   4057       1.3  riastrad 		frame->s3d_struct = s3d_structure_from_display_mode(mode);
   4058       1.1  riastrad 
   4059       1.1  riastrad 	return 0;
   4060       1.1  riastrad }
   4061       1.3  riastrad EXPORT_SYMBOL(drm_hdmi_vendor_infoframe_from_display_mode);
   4062  1.5.16.1  pgoyette 
   4063  1.5.16.1  pgoyette static int drm_parse_display_id(struct drm_connector *connector,
   4064  1.5.16.1  pgoyette 				u8 *displayid, int length,
   4065  1.5.16.1  pgoyette 				bool is_edid_extension)
   4066  1.5.16.1  pgoyette {
   4067  1.5.16.1  pgoyette 	/* if this is an EDID extension the first byte will be 0x70 */
   4068  1.5.16.1  pgoyette 	int idx = 0;
   4069  1.5.16.1  pgoyette 	struct displayid_hdr *base;
   4070  1.5.16.1  pgoyette 	struct displayid_block *block;
   4071  1.5.16.1  pgoyette 	u8 csum = 0;
   4072  1.5.16.1  pgoyette 	int i;
   4073  1.5.16.1  pgoyette 
   4074  1.5.16.1  pgoyette 	if (is_edid_extension)
   4075  1.5.16.1  pgoyette 		idx = 1;
   4076  1.5.16.1  pgoyette 
   4077  1.5.16.1  pgoyette 	base = (struct displayid_hdr *)&displayid[idx];
   4078  1.5.16.1  pgoyette 
   4079  1.5.16.1  pgoyette 	DRM_DEBUG_KMS("base revision 0x%x, length %d, %d %d\n",
   4080  1.5.16.1  pgoyette 		      base->rev, base->bytes, base->prod_id, base->ext_count);
   4081  1.5.16.1  pgoyette 
   4082  1.5.16.1  pgoyette 	if (base->bytes + 5 > length - idx)
   4083  1.5.16.1  pgoyette 		return -EINVAL;
   4084  1.5.16.1  pgoyette 
   4085  1.5.16.1  pgoyette 	for (i = idx; i <= base->bytes + 5; i++) {
   4086  1.5.16.1  pgoyette 		csum += displayid[i];
   4087  1.5.16.1  pgoyette 	}
   4088  1.5.16.1  pgoyette 	if (csum) {
   4089  1.5.16.1  pgoyette 		DRM_ERROR("DisplayID checksum invalid, remainder is %d\n", csum);
   4090  1.5.16.1  pgoyette 		return -EINVAL;
   4091  1.5.16.1  pgoyette 	}
   4092  1.5.16.1  pgoyette 
   4093  1.5.16.1  pgoyette 	block = (struct displayid_block *)&displayid[idx + 4];
   4094  1.5.16.1  pgoyette 	DRM_DEBUG_KMS("block id %d, rev %d, len %d\n",
   4095  1.5.16.1  pgoyette 		      block->tag, block->rev, block->num_bytes);
   4096  1.5.16.1  pgoyette 
   4097  1.5.16.1  pgoyette 	switch (block->tag) {
   4098  1.5.16.1  pgoyette 	case DATA_BLOCK_TILED_DISPLAY: {
   4099  1.5.16.1  pgoyette 		struct displayid_tiled_block *tile = (struct displayid_tiled_block *)block;
   4100  1.5.16.1  pgoyette 
   4101  1.5.16.1  pgoyette 		u16 w, h;
   4102  1.5.16.1  pgoyette 		u8 tile_v_loc, tile_h_loc;
   4103  1.5.16.1  pgoyette 		u8 num_v_tile, num_h_tile;
   4104  1.5.16.1  pgoyette 		struct drm_tile_group *tg;
   4105  1.5.16.1  pgoyette 
   4106  1.5.16.1  pgoyette 		w = tile->tile_size[0] | tile->tile_size[1] << 8;
   4107  1.5.16.1  pgoyette 		h = tile->tile_size[2] | tile->tile_size[3] << 8;
   4108  1.5.16.1  pgoyette 
   4109  1.5.16.1  pgoyette 		num_v_tile = (tile->topo[0] & 0xf) | (tile->topo[2] & 0x30);
   4110  1.5.16.1  pgoyette 		num_h_tile = (tile->topo[0] >> 4) | ((tile->topo[2] >> 2) & 0x30);
   4111  1.5.16.1  pgoyette 		tile_v_loc = (tile->topo[1] & 0xf) | ((tile->topo[2] & 0x3) << 4);
   4112  1.5.16.1  pgoyette 		tile_h_loc = (tile->topo[1] >> 4) | (((tile->topo[2] >> 2) & 0x3) << 4);
   4113  1.5.16.1  pgoyette 
   4114  1.5.16.1  pgoyette 		connector->has_tile = true;
   4115  1.5.16.1  pgoyette 		if (tile->tile_cap & 0x80)
   4116  1.5.16.1  pgoyette 			connector->tile_is_single_monitor = true;
   4117  1.5.16.1  pgoyette 
   4118  1.5.16.1  pgoyette 		connector->num_h_tile = num_h_tile + 1;
   4119  1.5.16.1  pgoyette 		connector->num_v_tile = num_v_tile + 1;
   4120  1.5.16.1  pgoyette 		connector->tile_h_loc = tile_h_loc;
   4121  1.5.16.1  pgoyette 		connector->tile_v_loc = tile_v_loc;
   4122  1.5.16.1  pgoyette 		connector->tile_h_size = w + 1;
   4123  1.5.16.1  pgoyette 		connector->tile_v_size = h + 1;
   4124  1.5.16.1  pgoyette 
   4125  1.5.16.1  pgoyette 		DRM_DEBUG_KMS("tile cap 0x%x\n", tile->tile_cap);
   4126  1.5.16.1  pgoyette 		DRM_DEBUG_KMS("tile_size %d x %d\n", w + 1, h + 1);
   4127  1.5.16.1  pgoyette 		DRM_DEBUG_KMS("topo num tiles %dx%d, location %dx%d\n",
   4128  1.5.16.1  pgoyette 		       num_h_tile + 1, num_v_tile + 1, tile_h_loc, tile_v_loc);
   4129  1.5.16.1  pgoyette 		DRM_DEBUG_KMS("vend %c%c%c\n", tile->topology_id[0], tile->topology_id[1], tile->topology_id[2]);
   4130  1.5.16.1  pgoyette 
   4131  1.5.16.1  pgoyette 		tg = drm_mode_get_tile_group(connector->dev, tile->topology_id);
   4132  1.5.16.1  pgoyette 		if (!tg) {
   4133  1.5.16.1  pgoyette 			tg = drm_mode_create_tile_group(connector->dev, tile->topology_id);
   4134  1.5.16.1  pgoyette 		}
   4135  1.5.16.1  pgoyette 		if (!tg)
   4136  1.5.16.1  pgoyette 			return -ENOMEM;
   4137  1.5.16.1  pgoyette 
   4138  1.5.16.1  pgoyette 		if (connector->tile_group != tg) {
   4139  1.5.16.1  pgoyette 			/* if we haven't got a pointer,
   4140  1.5.16.1  pgoyette 			   take the reference, drop ref to old tile group */
   4141  1.5.16.1  pgoyette 			if (connector->tile_group) {
   4142  1.5.16.1  pgoyette 				drm_mode_put_tile_group(connector->dev, connector->tile_group);
   4143  1.5.16.1  pgoyette 			}
   4144  1.5.16.1  pgoyette 			connector->tile_group = tg;
   4145  1.5.16.1  pgoyette 		} else
   4146  1.5.16.1  pgoyette 			/* if same tile group, then release the ref we just took. */
   4147  1.5.16.1  pgoyette 			drm_mode_put_tile_group(connector->dev, tg);
   4148  1.5.16.1  pgoyette 	}
   4149  1.5.16.1  pgoyette 		break;
   4150  1.5.16.1  pgoyette 	default:
   4151  1.5.16.1  pgoyette 		printk("unknown displayid tag %d\n", block->tag);
   4152  1.5.16.1  pgoyette 		break;
   4153  1.5.16.1  pgoyette 	}
   4154  1.5.16.1  pgoyette 	return 0;
   4155  1.5.16.1  pgoyette }
   4156  1.5.16.1  pgoyette 
   4157  1.5.16.1  pgoyette static void drm_get_displayid(struct drm_connector *connector,
   4158  1.5.16.1  pgoyette 			      struct edid *edid)
   4159  1.5.16.1  pgoyette {
   4160  1.5.16.1  pgoyette 	void *displayid = NULL;
   4161  1.5.16.1  pgoyette 	int ret;
   4162  1.5.16.1  pgoyette 	connector->has_tile = false;
   4163  1.5.16.1  pgoyette 	displayid = drm_find_displayid_extension(edid);
   4164  1.5.16.1  pgoyette 	if (!displayid) {
   4165  1.5.16.1  pgoyette 		/* drop reference to any tile group we had */
   4166  1.5.16.1  pgoyette 		goto out_drop_ref;
   4167  1.5.16.1  pgoyette 	}
   4168  1.5.16.1  pgoyette 
   4169  1.5.16.1  pgoyette 	ret = drm_parse_display_id(connector, displayid, EDID_LENGTH, true);
   4170  1.5.16.1  pgoyette 	if (ret < 0)
   4171  1.5.16.1  pgoyette 		goto out_drop_ref;
   4172  1.5.16.1  pgoyette 	if (!connector->has_tile)
   4173  1.5.16.1  pgoyette 		goto out_drop_ref;
   4174  1.5.16.1  pgoyette 	return;
   4175  1.5.16.1  pgoyette out_drop_ref:
   4176  1.5.16.1  pgoyette 	if (connector->tile_group) {
   4177  1.5.16.1  pgoyette 		drm_mode_put_tile_group(connector->dev, connector->tile_group);
   4178  1.5.16.1  pgoyette 		connector->tile_group = NULL;
   4179  1.5.16.1  pgoyette 	}
   4180  1.5.16.1  pgoyette 	return;
   4181  1.5.16.1  pgoyette }
   4182