18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
48c2ecf20Sopenharmony_ci * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include <linux/via-core.h>
98c2ecf20Sopenharmony_ci#include "global.h"
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_cistruct io_reg CN400_ModeXregs[] = { {VIASR, SR10, 0xFF, 0x01},
128c2ecf20Sopenharmony_ci{VIASR, SR15, 0x02, 0x02},
138c2ecf20Sopenharmony_ci{VIASR, SR16, 0xBF, 0x08},
148c2ecf20Sopenharmony_ci{VIASR, SR17, 0xFF, 0x1F},
158c2ecf20Sopenharmony_ci{VIASR, SR18, 0xFF, 0x4E},
168c2ecf20Sopenharmony_ci{VIASR, SR1A, 0xFB, 0x08},
178c2ecf20Sopenharmony_ci{VIASR, SR1E, 0x0F, 0x01},
188c2ecf20Sopenharmony_ci{VIASR, SR2A, 0xFF, 0x00},
198c2ecf20Sopenharmony_ci{VIACR, CR32, 0xFF, 0x00},
208c2ecf20Sopenharmony_ci{VIACR, CR33, 0xFF, 0x00},
218c2ecf20Sopenharmony_ci{VIACR, CR35, 0xFF, 0x00},
228c2ecf20Sopenharmony_ci{VIACR, CR36, 0x08, 0x00},
238c2ecf20Sopenharmony_ci{VIACR, CR69, 0xFF, 0x00},
248c2ecf20Sopenharmony_ci{VIACR, CR6A, 0xFF, 0x40},
258c2ecf20Sopenharmony_ci{VIACR, CR6B, 0xFF, 0x00},
268c2ecf20Sopenharmony_ci{VIACR, CR88, 0xFF, 0x40},	/* LCD Panel Type                      */
278c2ecf20Sopenharmony_ci{VIACR, CR89, 0xFF, 0x00},	/* LCD Timing Control 0                */
288c2ecf20Sopenharmony_ci{VIACR, CR8A, 0xFF, 0x88},	/* LCD Timing Control 1                */
298c2ecf20Sopenharmony_ci{VIACR, CR8B, 0xFF, 0x69},	/* LCD Power Sequence Control 0        */
308c2ecf20Sopenharmony_ci{VIACR, CR8C, 0xFF, 0x57},	/* LCD Power Sequence Control 1        */
318c2ecf20Sopenharmony_ci{VIACR, CR8D, 0xFF, 0x00},	/* LCD Power Sequence Control 2        */
328c2ecf20Sopenharmony_ci{VIACR, CR8E, 0xFF, 0x7B},	/* LCD Power Sequence Control 3        */
338c2ecf20Sopenharmony_ci{VIACR, CR8F, 0xFF, 0x03},	/* LCD Power Sequence Control 4        */
348c2ecf20Sopenharmony_ci{VIACR, CR90, 0xFF, 0x30},	/* LCD Power Sequence Control 5        */
358c2ecf20Sopenharmony_ci{VIACR, CR91, 0xFF, 0xA0},	/* 24/12 bit LVDS Data off             */
368c2ecf20Sopenharmony_ci{VIACR, CR96, 0xFF, 0x00},
378c2ecf20Sopenharmony_ci{VIACR, CR97, 0xFF, 0x00},
388c2ecf20Sopenharmony_ci{VIACR, CR99, 0xFF, 0x00},
398c2ecf20Sopenharmony_ci{VIACR, CR9B, 0xFF, 0x00}
408c2ecf20Sopenharmony_ci};
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci/* Video Mode Table for VT3314 chipset*/
438c2ecf20Sopenharmony_ci/* Common Setting for Video Mode */
448c2ecf20Sopenharmony_cistruct io_reg CN700_ModeXregs[] = { {VIASR, SR10, 0xFF, 0x01},
458c2ecf20Sopenharmony_ci{VIASR, SR15, 0x02, 0x02},
468c2ecf20Sopenharmony_ci{VIASR, SR16, 0xBF, 0x08},
478c2ecf20Sopenharmony_ci{VIASR, SR17, 0xFF, 0x1F},
488c2ecf20Sopenharmony_ci{VIASR, SR18, 0xFF, 0x4E},
498c2ecf20Sopenharmony_ci{VIASR, SR1A, 0xFB, 0x82},
508c2ecf20Sopenharmony_ci{VIASR, SR1B, 0xFF, 0xF0},
518c2ecf20Sopenharmony_ci{VIASR, SR1F, 0xFF, 0x00},
528c2ecf20Sopenharmony_ci{VIASR, SR1E, 0xFF, 0x01},
538c2ecf20Sopenharmony_ci{VIASR, SR22, 0xFF, 0x1F},
548c2ecf20Sopenharmony_ci{VIASR, SR2A, 0x0F, 0x00},
558c2ecf20Sopenharmony_ci{VIASR, SR2E, 0xFF, 0xFF},
568c2ecf20Sopenharmony_ci{VIASR, SR3F, 0xFF, 0xFF},
578c2ecf20Sopenharmony_ci{VIASR, SR40, 0xF7, 0x00},
588c2ecf20Sopenharmony_ci{VIASR, CR30, 0xFF, 0x04},
598c2ecf20Sopenharmony_ci{VIACR, CR32, 0xFF, 0x00},
608c2ecf20Sopenharmony_ci{VIACR, CR33, 0x7F, 0x00},
618c2ecf20Sopenharmony_ci{VIACR, CR35, 0xFF, 0x00},
628c2ecf20Sopenharmony_ci{VIACR, CR36, 0xFF, 0x31},
638c2ecf20Sopenharmony_ci{VIACR, CR41, 0xFF, 0x80},
648c2ecf20Sopenharmony_ci{VIACR, CR42, 0xFF, 0x00},
658c2ecf20Sopenharmony_ci{VIACR, CR55, 0x80, 0x00},
668c2ecf20Sopenharmony_ci{VIACR, CR5D, 0x80, 0x00},	/*Horizontal Retrace Start bit[11] should be 0*/
678c2ecf20Sopenharmony_ci{VIACR, CR68, 0xFF, 0x67},	/* Default FIFO For IGA2 */
688c2ecf20Sopenharmony_ci{VIACR, CR69, 0xFF, 0x00},
698c2ecf20Sopenharmony_ci{VIACR, CR6A, 0xFD, 0x40},
708c2ecf20Sopenharmony_ci{VIACR, CR6B, 0xFF, 0x00},
718c2ecf20Sopenharmony_ci{VIACR, CR77, 0xFF, 0x00},	/* LCD scaling Factor */
728c2ecf20Sopenharmony_ci{VIACR, CR78, 0xFF, 0x00},	/* LCD scaling Factor */
738c2ecf20Sopenharmony_ci{VIACR, CR79, 0xFF, 0x00},	/* LCD scaling Factor */
748c2ecf20Sopenharmony_ci{VIACR, CR9F, 0x03, 0x00},	/* LCD scaling Factor */
758c2ecf20Sopenharmony_ci{VIACR, CR88, 0xFF, 0x40},	/* LCD Panel Type */
768c2ecf20Sopenharmony_ci{VIACR, CR89, 0xFF, 0x00},	/* LCD Timing Control 0 */
778c2ecf20Sopenharmony_ci{VIACR, CR8A, 0xFF, 0x88},	/* LCD Timing Control 1 */
788c2ecf20Sopenharmony_ci{VIACR, CR8B, 0xFF, 0x5D},	/* LCD Power Sequence Control 0 */
798c2ecf20Sopenharmony_ci{VIACR, CR8C, 0xFF, 0x2B},	/* LCD Power Sequence Control 1 */
808c2ecf20Sopenharmony_ci{VIACR, CR8D, 0xFF, 0x6F},	/* LCD Power Sequence Control 2 */
818c2ecf20Sopenharmony_ci{VIACR, CR8E, 0xFF, 0x2B},	/* LCD Power Sequence Control 3 */
828c2ecf20Sopenharmony_ci{VIACR, CR8F, 0xFF, 0x01},	/* LCD Power Sequence Control 4 */
838c2ecf20Sopenharmony_ci{VIACR, CR90, 0xFF, 0x01},	/* LCD Power Sequence Control 5 */
848c2ecf20Sopenharmony_ci{VIACR, CR91, 0xFF, 0xA0},	/* 24/12 bit LVDS Data off */
858c2ecf20Sopenharmony_ci{VIACR, CR96, 0xFF, 0x00},
868c2ecf20Sopenharmony_ci{VIACR, CR97, 0xFF, 0x00},
878c2ecf20Sopenharmony_ci{VIACR, CR99, 0xFF, 0x00},
888c2ecf20Sopenharmony_ci{VIACR, CR9B, 0xFF, 0x00},
898c2ecf20Sopenharmony_ci{VIACR, CR9D, 0xFF, 0x80},
908c2ecf20Sopenharmony_ci{VIACR, CR9E, 0xFF, 0x80}
918c2ecf20Sopenharmony_ci};
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_cistruct io_reg KM400_ModeXregs[] = {
948c2ecf20Sopenharmony_ci	{VIASR, SR10, 0xFF, 0x01},	/* Unlock Register                 */
958c2ecf20Sopenharmony_ci	{VIASR, SR16, 0xFF, 0x08},	/* Display FIFO threshold Control  */
968c2ecf20Sopenharmony_ci	{VIASR, SR17, 0xFF, 0x1F},	/* Display FIFO Control            */
978c2ecf20Sopenharmony_ci	{VIASR, SR18, 0xFF, 0x4E},	/* GFX PREQ threshold              */
988c2ecf20Sopenharmony_ci	{VIASR, SR1A, 0xFF, 0x0a},	/* GFX PREQ threshold              */
998c2ecf20Sopenharmony_ci	{VIASR, SR1F, 0xFF, 0x00},	/* Memory Control 0                */
1008c2ecf20Sopenharmony_ci	{VIASR, SR1B, 0xFF, 0xF0},	/* Power Management Control 0      */
1018c2ecf20Sopenharmony_ci	{VIASR, SR1E, 0xFF, 0x01},	/* Power Management Control        */
1028c2ecf20Sopenharmony_ci	{VIASR, SR20, 0xFF, 0x00},	/* Sequencer Arbiter Control 0     */
1038c2ecf20Sopenharmony_ci	{VIASR, SR21, 0xFF, 0x00},	/* Sequencer Arbiter Control 1     */
1048c2ecf20Sopenharmony_ci	{VIASR, SR22, 0xFF, 0x1F},	/* Display Arbiter Control 1       */
1058c2ecf20Sopenharmony_ci	{VIASR, SR2A, 0xFF, 0x00},	/* Power Management Control 5      */
1068c2ecf20Sopenharmony_ci	{VIASR, SR2D, 0xFF, 0xFF},	/* Power Management Control 1      */
1078c2ecf20Sopenharmony_ci	{VIASR, SR2E, 0xFF, 0xFF},	/* Power Management Control 2      */
1088c2ecf20Sopenharmony_ci	{VIACR, CR33, 0xFF, 0x00},
1098c2ecf20Sopenharmony_ci	{VIACR, CR55, 0x80, 0x00},
1108c2ecf20Sopenharmony_ci	{VIACR, CR5D, 0x80, 0x00},
1118c2ecf20Sopenharmony_ci	{VIACR, CR36, 0xFF, 0x01},	/* Power Mangement 3                  */
1128c2ecf20Sopenharmony_ci	{VIACR, CR68, 0xFF, 0x67},	/* Default FIFO For IGA2              */
1138c2ecf20Sopenharmony_ci	{VIACR, CR6A, 0x20, 0x20},	/* Extended FIFO On                   */
1148c2ecf20Sopenharmony_ci	{VIACR, CR88, 0xFF, 0x40},	/* LCD Panel Type                     */
1158c2ecf20Sopenharmony_ci	{VIACR, CR89, 0xFF, 0x00},	/* LCD Timing Control 0               */
1168c2ecf20Sopenharmony_ci	{VIACR, CR8A, 0xFF, 0x88},	/* LCD Timing Control 1               */
1178c2ecf20Sopenharmony_ci	{VIACR, CR8B, 0xFF, 0x2D},	/* LCD Power Sequence Control 0       */
1188c2ecf20Sopenharmony_ci	{VIACR, CR8C, 0xFF, 0x2D},	/* LCD Power Sequence Control 1       */
1198c2ecf20Sopenharmony_ci	{VIACR, CR8D, 0xFF, 0xC8},	/* LCD Power Sequence Control 2       */
1208c2ecf20Sopenharmony_ci	{VIACR, CR8E, 0xFF, 0x36},	/* LCD Power Sequence Control 3       */
1218c2ecf20Sopenharmony_ci	{VIACR, CR8F, 0xFF, 0x00},	/* LCD Power Sequence Control 4       */
1228c2ecf20Sopenharmony_ci	{VIACR, CR90, 0xFF, 0x10},	/* LCD Power Sequence Control 5       */
1238c2ecf20Sopenharmony_ci	{VIACR, CR91, 0xFF, 0xA0},	/* 24/12 bit LVDS Data off            */
1248c2ecf20Sopenharmony_ci	{VIACR, CR96, 0xFF, 0x03},	/* DVP0        ; DVP0 Clock Skew */
1258c2ecf20Sopenharmony_ci	{VIACR, CR97, 0xFF, 0x03},	/* DFP high    ; DFPH Clock Skew */
1268c2ecf20Sopenharmony_ci	{VIACR, CR99, 0xFF, 0x03},	/* DFP low           ; DFPL Clock Skew*/
1278c2ecf20Sopenharmony_ci	{VIACR, CR9B, 0xFF, 0x07}	/* DVI on DVP1       ; DVP1 Clock Skew*/
1288c2ecf20Sopenharmony_ci};
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ci/* For VT3324: Common Setting for Video Mode */
1318c2ecf20Sopenharmony_cistruct io_reg CX700_ModeXregs[] = { {VIASR, SR10, 0xFF, 0x01},
1328c2ecf20Sopenharmony_ci{VIASR, SR15, 0x02, 0x02},
1338c2ecf20Sopenharmony_ci{VIASR, SR16, 0xBF, 0x08},
1348c2ecf20Sopenharmony_ci{VIASR, SR17, 0xFF, 0x1F},
1358c2ecf20Sopenharmony_ci{VIASR, SR18, 0xFF, 0x4E},
1368c2ecf20Sopenharmony_ci{VIASR, SR1A, 0xFB, 0x08},
1378c2ecf20Sopenharmony_ci{VIASR, SR1B, 0xFF, 0xF0},
1388c2ecf20Sopenharmony_ci{VIASR, SR1E, 0xFF, 0x01},
1398c2ecf20Sopenharmony_ci{VIASR, SR2A, 0xFF, 0x00},
1408c2ecf20Sopenharmony_ci{VIASR, SR2D, 0xC0, 0xC0},	/* delayed E3_ECK */
1418c2ecf20Sopenharmony_ci{VIACR, CR32, 0xFF, 0x00},
1428c2ecf20Sopenharmony_ci{VIACR, CR33, 0xFF, 0x00},
1438c2ecf20Sopenharmony_ci{VIACR, CR35, 0xFF, 0x00},
1448c2ecf20Sopenharmony_ci{VIACR, CR36, 0x08, 0x00},
1458c2ecf20Sopenharmony_ci{VIACR, CR47, 0xC8, 0x00},	/* Clear VCK Plus. */
1468c2ecf20Sopenharmony_ci{VIACR, CR69, 0xFF, 0x00},
1478c2ecf20Sopenharmony_ci{VIACR, CR6A, 0xFF, 0x40},
1488c2ecf20Sopenharmony_ci{VIACR, CR6B, 0xFF, 0x00},
1498c2ecf20Sopenharmony_ci{VIACR, CR88, 0xFF, 0x40},	/* LCD Panel Type                      */
1508c2ecf20Sopenharmony_ci{VIACR, CR89, 0xFF, 0x00},	/* LCD Timing Control 0                */
1518c2ecf20Sopenharmony_ci{VIACR, CR8A, 0xFF, 0x88},	/* LCD Timing Control 1                */
1528c2ecf20Sopenharmony_ci{VIACR, CRD4, 0xFF, 0x81},	/* Second power sequence control       */
1538c2ecf20Sopenharmony_ci{VIACR, CR8B, 0xFF, 0x5D},	/* LCD Power Sequence Control 0        */
1548c2ecf20Sopenharmony_ci{VIACR, CR8C, 0xFF, 0x2B},	/* LCD Power Sequence Control 1        */
1558c2ecf20Sopenharmony_ci{VIACR, CR8D, 0xFF, 0x6F},	/* LCD Power Sequence Control 2        */
1568c2ecf20Sopenharmony_ci{VIACR, CR8E, 0xFF, 0x2B},	/* LCD Power Sequence Control 3        */
1578c2ecf20Sopenharmony_ci{VIACR, CR8F, 0xFF, 0x01},	/* LCD Power Sequence Control 4        */
1588c2ecf20Sopenharmony_ci{VIACR, CR90, 0xFF, 0x01},	/* LCD Power Sequence Control 5        */
1598c2ecf20Sopenharmony_ci{VIACR, CR91, 0xFF, 0x80},	/* 24/12 bit LVDS Data off             */
1608c2ecf20Sopenharmony_ci{VIACR, CR96, 0xFF, 0x00},
1618c2ecf20Sopenharmony_ci{VIACR, CR97, 0xFF, 0x00},
1628c2ecf20Sopenharmony_ci{VIACR, CR99, 0xFF, 0x00},
1638c2ecf20Sopenharmony_ci{VIACR, CR9B, 0xFF, 0x00}
1648c2ecf20Sopenharmony_ci};
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_cistruct io_reg VX855_ModeXregs[] = {
1678c2ecf20Sopenharmony_ci{VIASR, SR10, 0xFF, 0x01},
1688c2ecf20Sopenharmony_ci{VIASR, SR15, 0x02, 0x02},
1698c2ecf20Sopenharmony_ci{VIASR, SR16, 0xBF, 0x08},
1708c2ecf20Sopenharmony_ci{VIASR, SR17, 0xFF, 0x1F},
1718c2ecf20Sopenharmony_ci{VIASR, SR18, 0xFF, 0x4E},
1728c2ecf20Sopenharmony_ci{VIASR, SR1A, 0xFB, 0x08},
1738c2ecf20Sopenharmony_ci{VIASR, SR1B, 0xFF, 0xF0},
1748c2ecf20Sopenharmony_ci{VIASR, SR1E, 0x07, 0x01},
1758c2ecf20Sopenharmony_ci{VIASR, SR2A, 0xF0, 0x00},
1768c2ecf20Sopenharmony_ci{VIASR, SR58, 0xFF, 0x00},
1778c2ecf20Sopenharmony_ci{VIASR, SR59, 0xFF, 0x00},
1788c2ecf20Sopenharmony_ci{VIASR, SR2D, 0xC0, 0xC0},	/* delayed E3_ECK */
1798c2ecf20Sopenharmony_ci{VIACR, CR32, 0xFF, 0x00},
1808c2ecf20Sopenharmony_ci{VIACR, CR33, 0x7F, 0x00},
1818c2ecf20Sopenharmony_ci{VIACR, CR35, 0xFF, 0x00},
1828c2ecf20Sopenharmony_ci{VIACR, CR36, 0x08, 0x00},
1838c2ecf20Sopenharmony_ci{VIACR, CR69, 0xFF, 0x00},
1848c2ecf20Sopenharmony_ci{VIACR, CR6A, 0xFD, 0x60},
1858c2ecf20Sopenharmony_ci{VIACR, CR6B, 0xFF, 0x00},
1868c2ecf20Sopenharmony_ci{VIACR, CR88, 0xFF, 0x40},          /* LCD Panel Type                      */
1878c2ecf20Sopenharmony_ci{VIACR, CR89, 0xFF, 0x00},          /* LCD Timing Control 0                */
1888c2ecf20Sopenharmony_ci{VIACR, CR8A, 0xFF, 0x88},          /* LCD Timing Control 1                */
1898c2ecf20Sopenharmony_ci{VIACR, CRD4, 0xFF, 0x81},          /* Second power sequence control       */
1908c2ecf20Sopenharmony_ci{VIACR, CR91, 0xFF, 0x80},          /* 24/12 bit LVDS Data off             */
1918c2ecf20Sopenharmony_ci{VIACR, CR96, 0xFF, 0x00},
1928c2ecf20Sopenharmony_ci{VIACR, CR97, 0xFF, 0x00},
1938c2ecf20Sopenharmony_ci{VIACR, CR99, 0xFF, 0x00},
1948c2ecf20Sopenharmony_ci{VIACR, CR9B, 0xFF, 0x00},
1958c2ecf20Sopenharmony_ci{VIACR, CRD2, 0xFF, 0xFF}           /* TMDS/LVDS control register.         */
1968c2ecf20Sopenharmony_ci};
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_ci/* Video Mode Table */
1998c2ecf20Sopenharmony_ci/* Common Setting for Video Mode */
2008c2ecf20Sopenharmony_cistruct io_reg CLE266_ModeXregs[] = { {VIASR, SR1E, 0xF0, 0x00},
2018c2ecf20Sopenharmony_ci{VIASR, SR2A, 0x0F, 0x00},
2028c2ecf20Sopenharmony_ci{VIASR, SR15, 0x02, 0x02},
2038c2ecf20Sopenharmony_ci{VIASR, SR16, 0xBF, 0x08},
2048c2ecf20Sopenharmony_ci{VIASR, SR17, 0xFF, 0x1F},
2058c2ecf20Sopenharmony_ci{VIASR, SR18, 0xFF, 0x4E},
2068c2ecf20Sopenharmony_ci{VIASR, SR1A, 0xFB, 0x08},
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci{VIACR, CR32, 0xFF, 0x00},
2098c2ecf20Sopenharmony_ci{VIACR, CR35, 0xFF, 0x00},
2108c2ecf20Sopenharmony_ci{VIACR, CR36, 0x08, 0x00},
2118c2ecf20Sopenharmony_ci{VIACR, CR6A, 0xFF, 0x80},
2128c2ecf20Sopenharmony_ci{VIACR, CR6A, 0xFF, 0xC0},
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci{VIACR, CR55, 0x80, 0x00},
2158c2ecf20Sopenharmony_ci{VIACR, CR5D, 0x80, 0x00},
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ci{VIAGR, GR20, 0xFF, 0x00},
2188c2ecf20Sopenharmony_ci{VIAGR, GR21, 0xFF, 0x00},
2198c2ecf20Sopenharmony_ci{VIAGR, GR22, 0xFF, 0x00},
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ci};
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_ci/* Mode:1024X768 */
2248c2ecf20Sopenharmony_cistruct io_reg PM1024x768[] = { {VIASR, 0x16, 0xBF, 0x0C},
2258c2ecf20Sopenharmony_ci{VIASR, 0x18, 0xFF, 0x4C}
2268c2ecf20Sopenharmony_ci};
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_cistruct patch_table res_patch_table[] = {
2298c2ecf20Sopenharmony_ci	{ARRAY_SIZE(PM1024x768), PM1024x768}
2308c2ecf20Sopenharmony_ci};
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ci/* struct VPITTable {
2338c2ecf20Sopenharmony_ci	unsigned char  Misc;
2348c2ecf20Sopenharmony_ci	unsigned char  SR[StdSR];
2358c2ecf20Sopenharmony_ci	unsigned char  CR[StdCR];
2368c2ecf20Sopenharmony_ci	unsigned char  GR[StdGR];
2378c2ecf20Sopenharmony_ci	unsigned char  AR[StdAR];
2388c2ecf20Sopenharmony_ci };*/
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_cistruct VPITTable VPIT = {
2418c2ecf20Sopenharmony_ci	/* Msic */
2428c2ecf20Sopenharmony_ci	0xC7,
2438c2ecf20Sopenharmony_ci	/* Sequencer */
2448c2ecf20Sopenharmony_ci	{0x01, 0x0F, 0x00, 0x0E},
2458c2ecf20Sopenharmony_ci	/* Graphic Controller */
2468c2ecf20Sopenharmony_ci	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0F, 0xFF},
2478c2ecf20Sopenharmony_ci	/* Attribute Controller */
2488c2ecf20Sopenharmony_ci	{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
2498c2ecf20Sopenharmony_ci	 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
2508c2ecf20Sopenharmony_ci	 0x01, 0x00, 0x0F, 0x00}
2518c2ecf20Sopenharmony_ci};
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_ci/********************/
2548c2ecf20Sopenharmony_ci/* Mode Table       */
2558c2ecf20Sopenharmony_ci/********************/
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_cistatic const struct fb_videomode viafb_modes[] = {
2588c2ecf20Sopenharmony_ci	{NULL, 60, 480, 640, 40285, 72, 24, 19, 1, 48, 3, FB_SYNC_VERT_HIGH_ACT, 0, 0},
2598c2ecf20Sopenharmony_ci	{NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2, 0, 0, 0},
2608c2ecf20Sopenharmony_ci	{NULL, 75, 640, 480, 31746, 120, 16, 16, 1, 64, 3, 0, 0, 0},
2618c2ecf20Sopenharmony_ci	{NULL, 85, 640, 480, 27780, 80, 56, 25, 1, 56, 3, 0, 0, 0},
2628c2ecf20Sopenharmony_ci	{NULL, 100, 640, 480, 23167, 104, 40, 25, 1, 64, 3, FB_SYNC_VERT_HIGH_ACT, 0, 0},
2638c2ecf20Sopenharmony_ci	{NULL, 120, 640, 480, 19081, 104, 40, 31, 1, 64, 3, FB_SYNC_VERT_HIGH_ACT, 0, 0},
2648c2ecf20Sopenharmony_ci	{NULL, 60, 720, 480, 37426, 88, 16, 13, 1, 72, 3, FB_SYNC_VERT_HIGH_ACT, 0, 0},
2658c2ecf20Sopenharmony_ci	{NULL, 60, 720, 576, 30611, 96, 24, 17, 1, 72, 3, FB_SYNC_VERT_HIGH_ACT, 0, 0},
2668c2ecf20Sopenharmony_ci	{NULL, 60, 800, 600, 25131, 88, 40, 23, 1, 128, 4, FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, 0, 0},
2678c2ecf20Sopenharmony_ci	{NULL, 75, 800, 600, 20202, 160, 16, 21, 1, 80, 3, FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, 0, 0},
2688c2ecf20Sopenharmony_ci	{NULL, 85, 800, 600, 17790, 152, 32, 27, 1, 64, 3, FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, 0, 0},
2698c2ecf20Sopenharmony_ci	{NULL, 100, 800, 600, 14667, 136, 48, 32, 1, 88, 3, FB_SYNC_VERT_HIGH_ACT, 0, 0},
2708c2ecf20Sopenharmony_ci	{NULL, 120, 800, 600, 11911, 144, 56, 39, 1, 88, 3, FB_SYNC_VERT_HIGH_ACT, 0, 0},
2718c2ecf20Sopenharmony_ci	{NULL, 60, 800, 480, 33602, 96, 24, 10, 3, 72, 7, FB_SYNC_VERT_HIGH_ACT, 0, 0},
2728c2ecf20Sopenharmony_ci	{NULL, 60, 848, 480, 31565, 104, 24, 12, 3, 80, 5, FB_SYNC_VERT_HIGH_ACT, 0, 0},
2738c2ecf20Sopenharmony_ci	{NULL, 60, 856, 480, 31517, 104, 16, 13, 1, 88, 3, FB_SYNC_VERT_HIGH_ACT, 0, 0},
2748c2ecf20Sopenharmony_ci	{NULL, 60, 1024, 512, 24218, 136, 32, 15, 1, 104, 3, FB_SYNC_VERT_HIGH_ACT, 0, 0},
2758c2ecf20Sopenharmony_ci	{NULL, 60, 1024, 600, 20423, 144, 40, 18, 1, 104, 3, FB_SYNC_VERT_HIGH_ACT, 0, 0},
2768c2ecf20Sopenharmony_ci	{NULL, 60, 1024, 768, 15385, 160, 24, 29, 3, 136, 6, 0, 0, 0},
2778c2ecf20Sopenharmony_ci	{NULL, 75, 1024, 768, 12703, 176, 16, 28, 1, 96, 3, FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, 0, 0},
2788c2ecf20Sopenharmony_ci	{NULL, 85, 1024, 768, 10581, 208, 48, 36, 1, 96, 3, FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, 0, 0},
2798c2ecf20Sopenharmony_ci	{NULL, 100, 1024, 768, 8825, 184, 72, 42, 1, 112, 3, FB_SYNC_VERT_HIGH_ACT, 0, 0},
2808c2ecf20Sopenharmony_ci	{NULL, 75, 1152, 864, 9259, 256, 64, 32, 1, 128, 3, FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, 0, 0},
2818c2ecf20Sopenharmony_ci	{NULL, 60, 1280, 768, 12478, 200, 64, 23, 1, 136, 3, FB_SYNC_VERT_HIGH_ACT, 0, 0},
2828c2ecf20Sopenharmony_ci	{NULL, 50, 1280, 768, 15342, 184, 56, 19, 1, 128, 3, FB_SYNC_VERT_HIGH_ACT, 0, 0},
2838c2ecf20Sopenharmony_ci	{NULL, 60, 960, 600, 21964, 128, 32, 15, 3, 96, 6, FB_SYNC_VERT_HIGH_ACT, 0, 0},
2848c2ecf20Sopenharmony_ci	{NULL, 60, 1000, 600, 20803, 144, 40, 18, 1, 104, 3, FB_SYNC_VERT_HIGH_ACT, 0, 0},
2858c2ecf20Sopenharmony_ci	{NULL, 60, 1024, 576, 21278, 144, 40, 17, 1, 104, 3, FB_SYNC_VERT_HIGH_ACT, 0, 0},
2868c2ecf20Sopenharmony_ci	{NULL, 60, 1088, 612, 18825, 152, 48, 16, 3, 104, 5, FB_SYNC_VERT_HIGH_ACT, 0, 0},
2878c2ecf20Sopenharmony_ci	{NULL, 60, 1152, 720, 14974, 168, 56, 19, 3, 112, 6, FB_SYNC_VERT_HIGH_ACT, 0, 0},
2888c2ecf20Sopenharmony_ci	{NULL, 60, 1200, 720, 14248, 184, 56, 22, 1, 128, 3, FB_SYNC_VERT_HIGH_ACT, 0, 0},
2898c2ecf20Sopenharmony_ci	{NULL, 49, 1200, 900, 17703, 21, 11, 1, 1, 32, 10, FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, 0, 0},
2908c2ecf20Sopenharmony_ci	{NULL, 60, 1280, 600, 16259, 184, 56, 18, 1, 128, 3, FB_SYNC_VERT_HIGH_ACT, 0, 0},
2918c2ecf20Sopenharmony_ci	{NULL, 60, 1280, 800, 11938, 200, 72, 22, 3, 128, 6, FB_SYNC_VERT_HIGH_ACT, 0, 0},
2928c2ecf20Sopenharmony_ci	{NULL, 60, 1280, 960, 9259, 312, 96, 36, 1, 112, 3, FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, 0, 0},
2938c2ecf20Sopenharmony_ci	{NULL, 60, 1280, 1024, 9262, 248, 48, 38, 1, 112, 3, FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, 0, 0},
2948c2ecf20Sopenharmony_ci	{NULL, 75, 1280, 1024, 7409, 248, 16, 38, 1, 144, 3, FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, 0, 0},
2958c2ecf20Sopenharmony_ci	{NULL, 85, 1280, 1024, 6351, 224, 64, 44, 1, 160, 3, FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, 0, 0},
2968c2ecf20Sopenharmony_ci	{NULL, 60, 1360, 768, 11759, 208, 72, 22, 3, 136, 5, FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, 0, 0},
2978c2ecf20Sopenharmony_ci	{NULL, 60, 1368, 768, 11646, 216, 72, 23, 1, 144, 3, FB_SYNC_VERT_HIGH_ACT, 0, 0},
2988c2ecf20Sopenharmony_ci	{NULL, 50, 1368, 768, 14301, 200, 56, 19, 1, 144, 3, FB_SYNC_VERT_HIGH_ACT, 0, 0},
2998c2ecf20Sopenharmony_ci	{NULL, 60, 1368, 768, 11646, 216, 72, 23, 1, 144, 3, FB_SYNC_VERT_HIGH_ACT, 0, 0},
3008c2ecf20Sopenharmony_ci	{NULL, 60, 1440, 900, 9372, 232, 80, 25, 3, 152, 6, FB_SYNC_VERT_HIGH_ACT, 0, 0},
3018c2ecf20Sopenharmony_ci	{NULL, 75, 1440, 900, 7311, 248, 96, 33, 3, 152, 6, FB_SYNC_VERT_HIGH_ACT, 0, 0},
3028c2ecf20Sopenharmony_ci	{NULL, 60, 1440, 1040, 7993, 248, 96, 33, 1, 152, 3, FB_SYNC_VERT_HIGH_ACT, 0, 0},
3038c2ecf20Sopenharmony_ci	{NULL, 60, 1600, 900, 8449, 256, 88, 26, 3, 168, 5, FB_SYNC_VERT_HIGH_ACT, 0, 0},
3048c2ecf20Sopenharmony_ci	{NULL, 60, 1600, 1024, 7333, 272, 104, 32, 1, 168, 3, FB_SYNC_VERT_HIGH_ACT, 0, 0},
3058c2ecf20Sopenharmony_ci	{NULL, 60, 1600, 1200, 6172, 304, 64, 46, 1, 192, 3, FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, 0, 0},
3068c2ecf20Sopenharmony_ci	{NULL, 75, 1600, 1200, 4938, 304, 64, 46, 1, 192, 3, FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, 0, 0},
3078c2ecf20Sopenharmony_ci	{NULL, 60, 1680, 1050, 6832, 280, 104, 30, 3, 176, 6, 0, 0, 0},
3088c2ecf20Sopenharmony_ci	{NULL, 75, 1680, 1050, 5339, 296, 120, 40, 3, 176, 6, FB_SYNC_VERT_HIGH_ACT, 0, 0},
3098c2ecf20Sopenharmony_ci	{NULL, 60, 1792, 1344, 4883, 328, 128, 46, 1, 200, 3, FB_SYNC_VERT_HIGH_ACT, 0, 0},
3108c2ecf20Sopenharmony_ci	{NULL, 60, 1856, 1392, 4581, 352, 96, 43, 1, 224, 3, FB_SYNC_VERT_HIGH_ACT, 0, 0},
3118c2ecf20Sopenharmony_ci	{NULL, 60, 1920, 1440, 4273, 344, 128, 56, 1, 208, 3, FB_SYNC_VERT_HIGH_ACT, 0, 0},
3128c2ecf20Sopenharmony_ci	{NULL, 75, 1920, 1440, 3367, 352, 144, 56, 1, 224, 3, FB_SYNC_VERT_HIGH_ACT, 0, 0},
3138c2ecf20Sopenharmony_ci	{NULL, 60, 2048, 1536, 3738, 376, 152, 49, 3, 224, 4, FB_SYNC_VERT_HIGH_ACT, 0, 0},
3148c2ecf20Sopenharmony_ci	{NULL, 60, 1280, 720, 13484, 216, 112, 20, 5, 40, 5, FB_SYNC_VERT_HIGH_ACT, 0, 0},
3158c2ecf20Sopenharmony_ci	{NULL, 50, 1280, 720, 16538, 176, 48, 17, 1, 128, 3, FB_SYNC_VERT_HIGH_ACT, 0, 0},
3168c2ecf20Sopenharmony_ci	{NULL, 60, 1920, 1080, 5776, 328, 128, 32, 3, 200, 5, FB_SYNC_VERT_HIGH_ACT, 0, 0},
3178c2ecf20Sopenharmony_ci	{NULL, 60, 1920, 1200, 5164, 336, 136, 36, 3, 200, 6, FB_SYNC_VERT_HIGH_ACT, 0, 0},
3188c2ecf20Sopenharmony_ci	{NULL, 60, 1400, 1050, 8210, 232, 88, 32, 3, 144, 4, FB_SYNC_VERT_HIGH_ACT, 0, 0},
3198c2ecf20Sopenharmony_ci	{NULL, 75, 1400, 1050, 6398, 248, 104, 42, 3, 144, 4, FB_SYNC_VERT_HIGH_ACT, 0, 0} };
3208c2ecf20Sopenharmony_ci
3218c2ecf20Sopenharmony_cistatic const struct fb_videomode viafb_rb_modes[] = {
3228c2ecf20Sopenharmony_ci	{NULL, 60, 1360, 768, 13879, 80, 48, 14, 3, 32, 5, FB_SYNC_HOR_HIGH_ACT, 0, 0},
3238c2ecf20Sopenharmony_ci	{NULL, 60, 1440, 900, 11249, 80, 48, 17, 3, 32, 6, FB_SYNC_HOR_HIGH_ACT, 0, 0},
3248c2ecf20Sopenharmony_ci	{NULL, 60, 1400, 1050, 9892, 80, 48, 23, 3, 32, 4, FB_SYNC_HOR_HIGH_ACT, 0, 0},
3258c2ecf20Sopenharmony_ci	{NULL, 60, 1600, 900, 10226, 80, 48, 18, 3, 32, 5, FB_SYNC_HOR_HIGH_ACT, 0, 0},
3268c2ecf20Sopenharmony_ci	{NULL, 60, 1680, 1050, 8387, 80, 48, 21, 3, 32, 6, FB_SYNC_HOR_HIGH_ACT, 0, 0},
3278c2ecf20Sopenharmony_ci	{NULL, 60, 1920, 1080, 7212, 80, 48, 23, 3, 32, 5, FB_SYNC_HOR_HIGH_ACT, 0, 0},
3288c2ecf20Sopenharmony_ci	{NULL, 60, 1920, 1200, 6488, 80, 48, 26, 3, 32, 6, FB_SYNC_HOR_HIGH_ACT, 0, 0} };
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_ciint NUM_TOTAL_CN400_ModeXregs = ARRAY_SIZE(CN400_ModeXregs);
3318c2ecf20Sopenharmony_ciint NUM_TOTAL_CN700_ModeXregs = ARRAY_SIZE(CN700_ModeXregs);
3328c2ecf20Sopenharmony_ciint NUM_TOTAL_KM400_ModeXregs = ARRAY_SIZE(KM400_ModeXregs);
3338c2ecf20Sopenharmony_ciint NUM_TOTAL_CX700_ModeXregs = ARRAY_SIZE(CX700_ModeXregs);
3348c2ecf20Sopenharmony_ciint NUM_TOTAL_VX855_ModeXregs = ARRAY_SIZE(VX855_ModeXregs);
3358c2ecf20Sopenharmony_ciint NUM_TOTAL_CLE266_ModeXregs = ARRAY_SIZE(CLE266_ModeXregs);
3368c2ecf20Sopenharmony_ciint NUM_TOTAL_PATCH_MODE = ARRAY_SIZE(res_patch_table);
3378c2ecf20Sopenharmony_ci
3388c2ecf20Sopenharmony_ci
3398c2ecf20Sopenharmony_cistatic const struct fb_videomode *get_best_mode(
3408c2ecf20Sopenharmony_ci	const struct fb_videomode *modes, int n,
3418c2ecf20Sopenharmony_ci	int hres, int vres, int refresh)
3428c2ecf20Sopenharmony_ci{
3438c2ecf20Sopenharmony_ci	const struct fb_videomode *best = NULL;
3448c2ecf20Sopenharmony_ci	int i;
3458c2ecf20Sopenharmony_ci
3468c2ecf20Sopenharmony_ci	for (i = 0; i < n; i++) {
3478c2ecf20Sopenharmony_ci		if (modes[i].xres != hres || modes[i].yres != vres)
3488c2ecf20Sopenharmony_ci			continue;
3498c2ecf20Sopenharmony_ci
3508c2ecf20Sopenharmony_ci		if (!best || abs(modes[i].refresh - refresh) <
3518c2ecf20Sopenharmony_ci			abs(best->refresh - refresh))
3528c2ecf20Sopenharmony_ci			best = &modes[i];
3538c2ecf20Sopenharmony_ci	}
3548c2ecf20Sopenharmony_ci
3558c2ecf20Sopenharmony_ci	return best;
3568c2ecf20Sopenharmony_ci}
3578c2ecf20Sopenharmony_ci
3588c2ecf20Sopenharmony_ciconst struct fb_videomode *viafb_get_best_mode(int hres, int vres, int refresh)
3598c2ecf20Sopenharmony_ci{
3608c2ecf20Sopenharmony_ci	return get_best_mode(viafb_modes, ARRAY_SIZE(viafb_modes),
3618c2ecf20Sopenharmony_ci		hres, vres, refresh);
3628c2ecf20Sopenharmony_ci}
3638c2ecf20Sopenharmony_ci
3648c2ecf20Sopenharmony_ciconst struct fb_videomode *viafb_get_best_rb_mode(int hres, int vres,
3658c2ecf20Sopenharmony_ci	int refresh)
3668c2ecf20Sopenharmony_ci{
3678c2ecf20Sopenharmony_ci	return get_best_mode(viafb_rb_modes, ARRAY_SIZE(viafb_rb_modes),
3688c2ecf20Sopenharmony_ci		hres, vres, refresh);
3698c2ecf20Sopenharmony_ci}
370