#!/bin/bash

. /tmp/boot_info.txt

GraphContr=""
X11Driver=""
MesaDriver=""
KGraphDriver=""
MousePhys=""
USE_915resolution="n"
KMS="n"
CfgFile="/tmp/autoconfig.txt"
LogFile="/var/log/appmesg"
VideoRam=""
FIRMWARE=""

if [ -f $LogFile ]; then
 echo "-------------- start autoconfig ------------" >>$LogFile
else
 echo "-------------- start autoconfig ------------" >$LogFile
fi

function chk_GraphicsController() {
  
#      echo $class $device $vendor

    case "$vendor" in
    0x1002)
	KGraphDriver="radeon"
	GraphContr="ATI"
	case "$device" in
#	0x4354|0x4358|0x4554|0x4742|0x4744|0x4749|0x474c|0x474d|0x474e|0x474f|0x4750|0x4751|0x4752|0x4753|0x4754|0x4755|0x4756|0x4757|0x4758|0x4759|0x475a|0x4c42|0x4c44|0x4c47|0x4c49|0x4c4d|0x4c4e|0x4c50|0x4c51|0x4c52|0x4c53|0x5654|0x5655|0x5656)
#	    KGraphDriver=""
#	    X11Driver="mach64"
##	    KMS="y"
#	  ;;
	0x5148|0x514c|0x514d|0x4242)
	    GraphContr="R200"
	    X11Driver="ati"
	    FIRMWARE="radeon"
	    MesaDriver="r200"
	    KMS="y"
	  ;;
	0x4966|0x4967|0x4c64|0x4c66|0x4c67)
	    GraphContr="RV250"
	    X11Driver="ati"
	    FIRMWARE="radeon"
	    MesaDriver="r200"
	    KMS="y"
	  ;;
	0x4c6e|0x5960|0x5961|0x5962|0x5964|0x5965|0x5c61|0x5c63)
	    GraphContr="RV280"
	    X11Driver="ati"
	    FIRMWARE="radeon"
	    MesaDriver="r200"
	    KMS="y"
	  ;;
	0x5834|0x5835|0x7834|0x7835)
	    GraphContr="RS300"
	    X11Driver="ati"
	    FIRMWARE="radeon"
	    MesaDriver="r200"
	    KMS="y"
	  ;;
	0x9400|0x9401|0x9402|0x9403|0x9405|0x940a|0x940b|0x940f)
	    GraphContr="R600"
	    X11Driver="ati"
	    FIRMWARE="radeon_R600"
	    MesaDriver="r600"
	    KMS="y"
	  ;;
	0x94c0|0x94c1|0x94c3|0x94c4|0x94c5|0x94c6|0x94c7|0x94c8|0x94c9|0x94cb|0x94cc|0x94cd)
	    GraphContr="RV610"
	    X11Driver="ati"
	    FIRMWARE="radeon_R600"
	    MesaDriver="r600"
	    KMS="y"
	  ;;
	0x95c0|0x95c2|0x95c4|0x95c5|0x95c6|0x95c7|0x95c9|0x95cc|0x95cd|0x95ce|0x95cf)
	    GraphContr="RV620"
	    X11Driver="ati"
	    FIRMWARE="radeon_R600"
	    MesaDriver="r600"
	    KMS="y"
	  ;;
	0x9580|0x9581|0x9583|0x9586|0x9587|0x9588|0x9589|0x959a|0x958b|0x958c|0x958d|0x958e|0x958f)
	    GraphContr="RV630"
	    X11Driver="ati"
	    FIRMWARE="radeon_R600"
	    MesaDriver="r600"
	    KMS="y"
	  ;;
	0x9590|0x9591|0x9593|0x9595|0x9596|0x9597|0x9598|0x9599|0x959b)
	    GraphContr="RV635"
	    X11Driver="ati"
	    FIRMWARE="radeon_R600"
	    MesaDriver="r600"
	    KMS="y"
	  ;;
	0x9500|0x9501|0x9504|0x9505|0x9506|0x9507|0x9508|0x9509|0x950f|0x9511|0x9515|0x9517|0x9519)
	    GraphContr="RV670"
	    X11Driver="ati"
	    FIRMWARE="radeon_R600"
	    MesaDriver="r600"
	    KMS="y"
	  ;;
	0x9610|0x9611|0x9612|0x9613|0x9614|0x9615|0x9616)
	    GraphContr="RS780"
	    X11Driver="ati"
	    FIRMWARE="radeon_R600"
	    MesaDriver="r600"
	    KMS="y"
	  ;;
	0x9710|0x9711|0x9712|0x9713|0x9714|0x9715)
	    GraphContr="RS880"
	    X11Driver="ati"
	    FIRMWARE="radeon_R600"
	    MesaDriver="r600"
	    KMS="y"
	  ;;
	0x9540|0x9541|0x9542|0x954e|0x954f|0x9552|0x9553|0x9555|0x9557|0x955f)
	    GraphContr="RV710"
	    X11Driver="ati"
	    FIRMWARE="radeon_RV710"
	    MesaDriver="r600"
	    KMS="y"
	  ;;
	0x9480|0x9487|0x9488|0x9489|0x948a|0x948f|0x9490|0x9491|0x9495|0x9498|0x949c|0x949e|0x949f)
	    GraphContr="RV730"
	    X11Driver="ati"
	    FIRMWARE="radeon_RV710"
	    MesaDriver="r600"
	    KMS="y"
	  ;;
	0x94a0|0x94a1|0x94a3|0x94b1|0x94b3|0x94b4|0x94b5|0x94b9)
	    GraphContr="RV740"
	    X11Driver="ati"
	    FIRMWARE="radeon_RV710"
	    MesaDriver="r600"
	    KMS="y"
	  ;;
	0x9440|0x9441|0x9442|0x9443|0x9444|0x9446|0x944a|0x944b|0x944c|0x944e|0x9450|0x9452|0x9456|0x945a|0x945b|0x945e|0x9460|0x9462|0x946a|0x946b|0x947a|0x947b)
	    GraphContr="RV770"
	    X11Driver="ati"
	    FIRMWARE="radeon_RV710"
	    MesaDriver="r600"
	    KMS="y"
	  ;;
	0x6880|0x6888|0x6889|0x688a|0x688c|0x688d|0x6898|0x6899|0x689b|0x689e)
	    GraphContr="CYPRESS"
	    X11Driver="ati"
	    FIRMWARE="radeon_CYPRESS"
	    MesaDriver="r600"
	    KMS="y"
	  ;;
	0x689c|0x689d)
	    GraphContr="HEMLOCK"
	    X11Driver="ati"
	    FIRMWARE="radeon_CYPRESS"
	    MesaDriver="r600"
	    KMS="y"
	  ;;
	0x68a0|0x68a1|0x68a8|0x68a9|0x68b0|0x68b8|0x68b9|0x68be)
	    GraphContr="JUNIPER"
	    X11Driver="ati"
	    FIRMWARE="radeon_CYPRESS"
	    MesaDriver="r600"
	    KMS="y"
	  ;;
	0x68c0|0x68c1|0x68c8|0x68c9|0x68d8|0x68d9|0x68da|0x68de)
	    GraphContr="REDWOOD"
	    X11Driver="ati"
	    FIRMWARE="radeon_CYPRESS"
	    MesaDriver="r600"
	    KMS="y"
	  ;;
	0x68e0|0x68e1|0x68e4|0x68e5|0x68e8|0x68e9|0x68f1|0x68f8|0x68f9|0x68fe)
	    GraphContr="CEDAR"
	    X11Driver="ati"
	    FIRMWARE="radeon_CYPRESS"
	    MesaDriver="r600"
	    KMS="y"
	  ;;
	0x9802|0x9803|0x9804|0x9805|0x9806|0x9807|0x9808|0x9809|0x980a)
	    GraphContr="PALM"
	    X11Driver="ati"
	    FIRMWARE="radeon_SUMO"
	    MesaDriver="r600"
	    KMS="y"
	  ;;
	0x6700|0x6701|0x6702|0x6703|0x6704|0x6705|0x6706|0x6707|0x6708|0x6709|0x6718|0x6719|0x671c|0x671d|0x671f)
	    GraphContr="CAYMAN"
	    X11Driver="ati"
	    FIRMWARE="radeon_SUMO"
	    MesaDriver="r600"
	    KMS="y"
	  ;;
	0x6720|0x6721|0x6722|0x6723|0x6724|0x6725|0x6726|0x6727|0x6728|0x6729|0x6738|0x6739|0x673e)
	    GraphContr="BARTS"
	    X11Driver="ati"
	    FIRMWARE="radeon_SUMO"
	    MesaDriver="r600"
	    KMS="y"
	  ;;
	0x6740|0x6741|0x6742|0x6743|0x6744|0x6745|0x6746|0x6747|0x6748|0x6749|0x674a|0x6750|0x6751|0x6758|0x6759|0x675b|0x675d|0x675f|0x6840|0x6841|0x6842|0x6843|0x6849|0x6850|0x6858|0x6859)
	    GraphContr="TURKS"
	    X11Driver="ati"
	    FIRMWARE="radeon_SUMO"
	    MesaDriver="r600"
	    KMS="y"
	  ;;
	0x6760|0x6761|0x6762|0x6763|0x6764|0x6765|0x6766|0x6767|0x6768|0x6770|0x6771|0x6772|0x6778|0x6779|0x677b)
	    GraphContr="CAICOS"
	    X11Driver="ati"
	    FIRMWARE="radeon_SUMO"
	    MesaDriver="r600"
	    KMS="y"
	  ;;
	0x9640|0x9641|0x9647|0x9648|0x964a|0x964b|0x964c|0x964e|0x964f)
	    GraphContr="SUMO"
	    X11Driver="ati"
	    FIRMWARE="radeon_SUMO"
	    MesaDriver="r600"
	    KMS="y"
	  ;;
	0x9642|0x9643|0x9644|0x9645|0x9649)
	    GraphContr="SUMO2"
	    X11Driver="ati"
	    FIRMWARE="radeon_SUMO"
	    MesaDriver="r600"
	    KMS="y"
	  ;;
	0x9900|0x9901|0x9903|0x9904|0x9905|0x9906|0x9907|0x9908|0x9909|0x990a|0x990f|0x9910|0x9913|0x9917|0x9918|0x9919|0x9990|0x9991|0x9992|0x9993|0x9994|0x99a0|0x99a2|0x99a4)
	    GraphContr="ARUBA"
	    X11Driver="ati"
	    FIRMWARE="radeon_TAHITI"
	    MesaDriver="r600"
	    KMS="y"
	  ;;
#  include/pci_ids/radeonsi_pci_ids.h
	0x6780|0x6784|0x6768|0x676a|0x6790|0x6791|0x6792|0x6798|0x6799|0x679a|0x679b|0x679e|0x679f)
	    GraphContr="TAHITI"
	    X11Driver="ati"
	    FIRMWARE="radeon_TAHITI"
	    MesaDriver="radeonsi"
	    KMS="y"
	  ;;
	0x6800|0x6801|0x6802|0x6806|0x6808|0x6809|0x6810|0x6810|0x6816|0x6817|0x6818|0x6819)
	    GraphContr="PITCAIRN"
	    X11Driver="ati"
	    FIRMWARE="radeon_TAHITI"
	    MesaDriver="radeonsi"
	    KMS="y"
	  ;;
	0x6820|0x6821|0x6822|0x6823|0x6824|0x6825|0x6826|0x6827|0x6828|0x6829|0x682a|0x682b|0x682d|0x682f|0x6830|0x6831|0x6835|0x6837|0x6838|0x6839|0x683b|0x683d|0x683f)
	    GraphContr="VERDE"
	    X11Driver="ati"
	    FIRMWARE="radeon_TAHITI"
	    MesaDriver="radeonsi"
	    KMS="y"
	  ;;
	0x6600|0x6601|0x6602|0x6603|0x6604|0x6605|0x6606|0x6607|0x6608|0x6610|0x6611|0x6613|0x6620|0x6621|0x6623|0x6631)
	    GraphContr="OLAND"
	    X11Driver="ati"
	    FIRMWARE="radeon_TAHITI"
	    MesaDriver="radeonsi"
	    KMS="y"
	  ;;
# HAINAN has no display hw 
#	0x6660|0x6663|0x6664|0x6665|0x6667|0x666f)
#	    GraphContr="HAINAN"
#	    X11Driver="ati"
#	    FIRMWARE="radeon_TAHITI"
##	    MesaDriver="radeonsi"
#	    KMS="y"
#	  ;;
	0x6640|0x6641|0x6646|0x6647|0x6649|0x6650|0x6651|0x6658|0x665c|0x665d)
	    GraphContr="BONAIRE"
	    X11Driver="ati"
	    FIRMWARE="radeon_BONAIRE"
	    MesaDriver="radeonsi"
	    KMS="y"
	  ;;
	0x9830|0x9831|0x9832|0x9833|0x9834|0x9835|0x9836|0x9837|0x9838|0x9839|0x983a|0x983b|0x983c|0x983d|0x983e|0x983f)
	    GraphContr="KABINI"
	    X11Driver="ati"
	    FIRMWARE="radeon_BONAIRE"
	    MesaDriver="radeonsi"
	    KMS="y"
	  ;;
	0x9850|0x9851|0x9852|0x9853|0x9854|0x9855|0x9856|0x9857|0x9858|0x9859|0x985a|0x985b|0x985c|0x985d|0x985e|0x985f)
	    GraphContr="MULLINS"
	    X11Driver="ati"
	    FIRMWARE="radeon_BONAIRE"
	    MesaDriver="radeonsi"
	    KMS="y"
	  ;;
	0x1304|0x1305|0x1306|0x1307|0x1309|0x130a|0x130b|0x130c|0x130d|0x130e|0x130f|0x1310|0x1311|0x1312|0x1313|0x1315|0x1316|0x1317|0x1318|0x131b|0x131c|0x131d)
	    GraphContr="KAVERI"
	    X11Driver="ati"
	    FIRMWARE="radeon_BONAIRE"
	    MesaDriver="radeonsi"
	    KMS="y"
	  ;;
	0x67a0|0x67a1|0x67a2|0x67a8|0x67aa|0x67b0|0x67b1|0x67b8|0x67b9|0x67ba|0x67be)
	    GraphContr="HAWAII"
	    X11Driver="ati"
	    FIRMWARE="radeon_BONAIRE"
	    MesaDriver="radeonsi"
	    KMS="y"
	  ;;
	0x164e)
	    KGraphDriver="amdgpu"
	    GraphContr="RAPHAEL"
	    X11Driver="amdgpu"
#	    FIRMWARE="radeon_BONAIRE"
	    MesaDriver="radeonsi"
	    KMS="y"
	  ;;
	*)
	    KGraphDriver=
	    X11Driver="vesa"
	  ;;
	esac
      ;;
    0x1013)
	    GraphContr="Cirrus"
#	    X11Driver="cirrus"
	    X11Driver="vesa"
      ;;
    0x1023)
	    GraphContr="Trident"
#	    X11Driver="trident"
	    X11Driver="vesa"
      ;;
    0x102c)
	    GraphContr="Chips"
	    X11Driver="vesa"
#	    X11Driver="chips"
      ;;
    0x1078)
	    GraphContr="Cyrix"
	    X11Driver="vesa"
#	    X11Driver="cyrix"
      ;;
#    0x10de|0x12d2)
    0x10de)
	KGraphDriver="nouveau"
	MesaDriver="nouveau"
	X11Driver="nouveau"
	KMS="y"
	case "$device" in
	0x0020)
	    GraphContr="NV4"
	  ;;
	0x0028|0x0029|0x002a|0x002c|0x002d|0x00a0)
	    GraphContr="NV5"
	  ;;
	0x0100|0x0101)
	    GraphContr="NV10"
	  ;;
	0x0103)
	    GraphContr="NV10GL"
	  ;;
	0x0110|0x0111|0x01a0)
	    GraphContr="NV11"
	  ;;
	0x0112)
	    GraphContr="NV11M"
	  ;;
	0x0113)
	    GraphContr="NV11GL"
	  ;;
	0x0150|0x0151|0x0152)
	    GraphContr="NV15"
	  ;;
	0x0153)
	    GraphContr="NV15GL"
	  ;;
	0x0170|0x0171|0x0172|0x0173|0x017f)
	    GraphContr="NV17"
	  ;;
	0x0174|0x0175|0x0176|0x0177|0x0179)
	    GraphContr="NV17M"
	  ;;
	0x0178|0x017a|0x017b|0x017c)
	    GraphContr="NV17GL"
	  ;;
	0x00ff|0x0181|0x0182|0x0183|0x0184|0x0185|0x0189|0x018f)
	    GraphContr="NV18"
	  ;;
	0x0186|0x0187|0x018d)
	    GraphContr="NV18M"
	  ;;
	0x0188|0x018a|0x018b|0x018c)
	    GraphContr="NV18GL"
	  ;;
	0x0200|0x0201|0x0202)
	    GraphContr="NV20"
	  ;;
	0x0203)
	    GraphContr="NV20GL"
	  ;;
	0x0250|0x0251|0x0252|0x0253)
	    GraphContr="NV25"
	  ;;
	0x0258|0x0259|0x025b)
	    GraphContr="NV25GL"
	  ;;
	0x0280|0x0281|0x0282)
	    GraphContr="NV28"
	  ;;
	0x0286)
	    GraphContr="NV28M"
	  ;;
	0x0288|0x0289)
	    GraphContr="NV28GL"
	  ;;
	0x028c)
	    GraphContr="NV28GLM"
	  ;;
	0x02a0)
	    GraphContr="NV2A"
	  ;;
	0x0300|0x0301|0x0302)
	    GraphContr="NV30"
	  ;;
	0x0308|0x0309)
	    GraphContr="NV30GL"
	  ;;
	0x0311|0x0312|0x0314)
	    GraphContr="NV31"
	  ;;
	0x0316|0x031a|0x031b)
	    GraphContr="NV31M"
	  ;;
	0x0318)
	    GraphContr="NV31GL"
	  ;;
	0x031c)
	    GraphContr="NV31GLM"
	  ;;
	0x0320|0x0321|0x0322|0x0323|0x0326|0x0327|0x032f)
	    GraphContr="NV34"
	  ;;
	0x0324|0x0325|0x0328|0x0329|0x032c|0x032d)
	    GraphContr="NV34M"
	  ;;
	0x032a|0x032b)
	    GraphContr="NV34GL"
	  ;;
	0x0330|0x0331|0x0332|0x0334)
	    GraphContr="NV35"
	  ;;
	0x0338|0x033f)
	    GraphContr="NV35GL"
	  ;;
	0x00fa|0x0341|0x0342|0x0343|0x0344|0x034c|0x034d)
	    GraphContr="NV36"
	  ;;
	0x0347|0x0348)
	    GraphContr="NV36M"
	  ;;
	0x034e)
	    GraphContr="NV36GL"
	  ;;
	0x00fc|0x00fd)
	    GraphContr="NV37GL"
	  ;;
	0x00fb|0x00fe|0x0333)
	    GraphContr="NV38"
	  ;;
	0x0040|0x0041|0x0042|0x0043|0x0044|0x0045|0x0047|0x00f9)
	    GraphContr="NV40"
	  ;;
	0x004e|0x00f8)
	    GraphContr="NV40GL"
	  ;;
	0x00c0|0x00c1|0x00c2|0x00c3|0x00c5|0x00c6|0x00c7|0x00cf)
	    GraphContr="NV41"
	  ;;
	0x00c8|0x00c9)
	    GraphContr="NV41M"
	  ;;
	0x00ce)
	    GraphContr="NV41GL"
	  ;;
	0x00cc)
	    GraphContr="NV41GLM"
	  ;;
	0x00cd)
	    GraphContr="NV42GL"
	  ;;
	0x00f0|0x00f1|0x00f2|0x00f3|0x00f4|0x00f6|0x0140|0x0141|0x0142|0x0143|0x0145|0x0147|0x014a|0x014b|0x014f)
	    GraphContr="NV43"
	  ;;
	0x0144|0x0146|0x0148|0x0149)
	    GraphContr="NV43M"
	  ;;
	0x014d|0x014e)
	    GraphContr="NV43GL"
	  ;;
	0x0160|0x0161|0x0162|0x0163|0x0165|0x0168|0x0169|0x016a|0x016d|0x016e|0x016f|0x0222|0x0224)
	    GraphContr="NV44"
	  ;;
	0x0221)
	    GraphContr="NV44A"
	  ;;
	0x0164|0x0166|0x0167)
	    GraphContr="NV44M"
	  ;;
	0x0211|0x0212|0x0215|0x0218)
	    GraphContr="NV48"
	  ;;
	0x0241|0x0244|0x0245|0x0247)
	    GraphContr="C51"
	  ;;
	0x0242)
	    GraphContr="C51G"
	  ;;
	0x0240)
	    GraphContr="C51PV"
	  ;;
	0x03d1|0x03d2|0x03d5|0x03d6)
	    GraphContr="C61"
	  ;;
	0x0531|0x0533)
	    GraphContr="C67"
	  ;;
	0x053a|0x053b|0x053e)
	    GraphContr="C68"
	  ;;
	0x07e0|0x07e1|0x07e2|0x07e3|0x07e5)
	    GraphContr="C73"
	  ;;
	0x0840|0x0844|0x0845|0x0846|0x0847|0x0848|0x0849|0x084a|0x084b|0x084c|0x084d|0x084f)
	    GraphContr="C77"
	  ;;
	0x0860|0x0861|0x0862|0x0863|0x0864|0x0865|0x0866|0x0867|0x0868|0x0869|0x086a|0x086c|0x086d|0x086e|0x086f|0x0870|0x0871|0x0872|0x0873|0x087a)
	    GraphContr="C79"
	  ;;
	0x0090|0x0091|0x0092|0x0093|0x0095|0x0097)
	    GraphContr="G70"
	  ;;
	0x0098|0x0099)
	    GraphContr="G70M"
	  ;;
	0x009d)
	    GraphContr="G70GL"
	  ;;
	0x00f5|0x0290|0x0291|0x0292|0x0293|0x0294|0x0295|0x02e3|0x02e4)
	    GraphContr="G71"
	  ;;
	0x0297|0x0298|0x0299)
	    GraphContr="G71M"
	  ;;
	0x029c|0x029d|0x029e|0x029f)
	    GraphContr="G71GL"
	  ;;
	0x029a|0x029b)
	    GraphContr="G71GLM"
	  ;;
	0x01d0|0x01d1|0x01d2|0x01d3|0x01d5|0x01dd|0x01df)
	    GraphContr="G72"
	  ;;
	0x01d6|0x01d7|0x01d8|0x01d9|0x01da|0x01db)
	    GraphContr="G72M"
	  ;;
	0x01de)
	    GraphContr="G72GL"
	  ;;
	0x01dc)
	    GraphContr="G72GLM"
	  ;;
	0x02e0|0x02e1|0x02e2|0x038b|0x0390|0x0391|0x0392|0x0393|0x0394|0x0395|0x0396|0x039d|0x039f)
	    GraphContr="G73"
	  ;;
	0x0397|0x0398|0x0399|0x039a|0x039b)
	    GraphContr="G73M"
	  ;;
	0x039e)
	    GraphContr="G73GL"
	  ;;
	0x039c)
	    GraphContr="G73GLM"
	  ;;
	0x0190|0x0191|0x0192|0x0193|0x0194)
	    GraphContr="G80"
	  ;;
	0x0197|0x019d|0x019e)
	    GraphContr="G80GL"
	  ;;
	0x0400|0x0401|0x0402|0x0403|0x0404|0x0406)
	    GraphContr="G84"
	  ;;
	0x0405|0x0407|0x0408|0x0409)
	    GraphContr="G84M"
	  ;;
	0x040a|0x040e|0x040f)
	    GraphContr="G84GL"
	  ;;
	0x040b|0x040c|0x040d)
	    GraphContr="G84GLM"
	  ;;
	0x0420|0x0421|0x0422|0x0423|0x0424|0x042c|0x042e|0x042f)
	    GraphContr="G86"
	  ;;
	0x0425|0x0426|0x0427|0x0428|0x0429|0x042a|0x042b)
	    GraphContr="G86M"
	  ;;
	0x042d)
	    GraphContr="G86GLM"
	  ;;
	0x0410|0x0414|0x0600|0x0601|0x0602|0x0603|0x0604|0x0605|0x0606|0x0607|0x060d|0x060e|0x0610|0x0611|0x0612|0x0613|0x0614|0x0615)
	    GraphContr="G92"
	  ;;
	0x0608|0x0609|0x060a|0x060b|0x060c|0x060f|0x0617|0x0618)
	    GraphContr="G92M"
	  ;;
	0x0619|0x061a|0x061b)
	    GraphContr="G92GL"
	  ;;
	0x061c|0x061d|0x061e|0x061f)
	    GraphContr="G92GLM"
	  ;;
	0x0620|0x0621|0x0622|0x0623|0x0624|0x0625|0x0626|0x0627|0x062c|0x062d|0x062e|0x062f|0x0630|0x0633|0x0635|0x0637|0x063f)
	    GraphContr="G94"
	  ;;
	0x0628|0x062a|0x062b|0x0631|0x0632)
	    GraphContr="G94M"
	  ;;
	0x0638)
	    GraphContr="G94GL"
	  ;;
	0x063a)
	    GraphContr="G94GLM"
	  ;;
	0x0640|0x0641|0x0642|0x0643|0x0644|0x0645|0x0646|0x064d|0x064e|0x0655|0x0656|0x065b|0x065d|0x065f)
	    GraphContr="G96"
	  ;;
	0x0647|0x0648|0x0649|0x064a|0x064b|0x064c|0x0651|0x0652|0x0653|0x0654)
	    GraphContr="G96M"
	  ;;
	0x0658|0x0659)
	    GraphContr="G96GL"
	  ;;
	0x065a|0x065c)
	    GraphContr="G96GLM"
	  ;;
	0x06e0|0x06e1|0x06e2|0x06e3|0x06e4|0x06e6|0x06e7|0x06ed|0x06ee|0x06f8|0x06fa|0x06fd|0x06ff)
	    GraphContr="G98"
	  ;;
	0x06e5|0x06e8|0x06e9|0x06ea|0x06eb|0x06ec|0x06ef|0x06f1)
	    GraphContr="G98M"
	  ;;
	0x06f9)
	    GraphContr="G98GL"
	  ;;
	0x06fb)
	    GraphContr="G98GLM"
	  ;;
	0x06c0|0x06c4|0x06cd)
	    GraphContr="GF100"
	  ;;
	0x06ca)
	    GraphContr="GF100M"
	  ;;
	0x06d1|0x06d2|0x06d8|0x06d9|0x06dc|0x06dd|0x06de|0x06df)
	    GraphContr="GF100GL"
	  ;;
	0x06da)
	    GraphContr="GF100GLM"
	  ;;
	0x0e22|0x0e23|0x0e24)
	    GraphContr="GF104"
	  ;;
	0x0e30|0x0e31)
	    GraphContr="GF104M"
	  ;;
	0x0e3a|0x0e3b)
	    GraphContr="GF104GLM"
	  ;;
	0x0dc0|0x0dc4|0x0dc5|0x0dc6)
	    GraphContr="GF106"
	  ;;
	0x0dcd|0x0dce|0x0dd1|0x0dd2|0x0dd3|0x0dd6)
	    GraphContr="GF106M"
	  ;;
	0x0dd8)
	    GraphContr="GF106GL"
	  ;;
	0x0dda)
	    GraphContr="GF106GLM"
	  ;;
	0x0de0|0x0de1|0x0de2|0x0de4|0x0de5|0x0de7|0x0f00|0x0f01|0x0f02|0x0f06)
	    GraphContr="GF108"
	  ;;
	0x0de3|0x0de8|0x0de9|0x0dea|0x0deb|0x0dec|0x0ded|0x0dee|0x0def|0x0df0|0x0df1|0x0df2|0x0df3|0x0df4|0x0df5|0x0df6|0x0df7)
	    GraphContr="GF108M"
	  ;;
	0x0df8)
	    GraphContr="GF108GL"
	  ;;
	0x0df9|0x0dfa|0x0dfc)
	    GraphContr="GF108GLM"
	  ;;
	0x1080|0x1081|0x1082|0x1084|0x1086|0x1087|0x1088|0x1089|0x108b)
	    GraphContr="GF110"
	  ;;
	0x108e|0x1091|0x1094|0x1096|0x109b)
	    GraphContr="GF110GL"
	  ;;
	0x109a)
	    GraphContr="GF100GLM"
	  ;;
	0x1200|0x1201|0x1202|0x1203|0x1205|0x1206|0x1207|0x1208)
	    GraphContr="GF114"
	  ;;
	0x1210|0x1211|0x1212|0x1213)
	    GraphContr="GF114M"
	  ;;
	0x1241|0x1243|0x1244|0x1245|0x1249|0x124b)
	    GraphContr="GF116"
	  ;;
	0x1246|0x1247|0x1248|0x124d|0x1251)
	    GraphContr="GF116M"
	  ;;
	0x1140)
	    GraphContr="GF117M"
	  ;;
	0x1040|0x1042|0x1048|0x1049|0x104a|0x104b|0x104d|0x107c|0x107d)
	    GraphContr="GF119"
	  ;;
	0x1050|0x1051|0x1052|0x1054|0x1055|0x1056|0x1057|0x1058|0x1059|0x105a|0x105b)
	    GraphContr="GF119M"
	  ;;
	0x1180|0x1182|0x1183|0x1184|0x1185|0x1187|0x1188|0x1189|0x118c|0x118e|0x1191|0x1193|0x1195)
	    GraphContr="GK104"
	  ;;
	0x1198|0x1199|0x119a|0x119d|0x119e|0x119f|0x11a0|0x11a1|0x11a2|0x11a3|0x11a7)
	    GraphContr="GK104M"
	  ;;
	0x118a|0x118b|0x118d|0x118f|0x1194|0x11b0|0x11b1|0x11b4|0x11ba|0x11bb|0x11bf)
	    GraphContr="GK104GL"
	  ;;
	0x11b6|0x11b7|0x11bc|0x11bd|0x11be)
	    GraphContr="GK104GLM"
	  ;;
	0x11c0|0x11c2|0x11c3|0x11c4|0x11c5|0x11c6|0x11c7|0x11c8|0x11cb)
	    GraphContr="GK106"
	  ;;
	0x11e0|0x11e1|0x11e2|0x11e3|0x11e7)
	    GraphContr="GK106M"
	  ;;
	0x11fa)
	    GraphContr="GK106GL"
	  ;;
	0x11fc)
	    GraphContr="GK106GLM"
	  ;;
	0x0fc0|0x0fc1|0x0fc2|0x0fc6|0x0fc8|0x0fc9|0x0fe5|0x0fe6|0x0ff1|0x0ffd)
	    GraphContr="GK107"
	  ;;
	0x0fcd|0x0fce|0x0fd1|0x0fd2|0x0fd3|0x0fd4|0x0fd5|0x0fd8|0x0fd9|0x0fdb|0x0fdf|0x0fe0|0x0fe1|0x0fe2|0x0fe3|0x0fe4|0x0fe9|0x0fea|0x0fec|0x0fed|0x0fee)
	    GraphContr="GK107M"
	  ;;
	0x0fe7|0x0fef|0x0ff2|0x0ff3|0x0ff5|0x0ff7|0x0ff9|0x0ffa|0x0ffe|0x0fff)
	    GraphContr="GK107GL"
	  ;;
	0x0ff6|0x0ff8|0x0ffb|0x0ffc)
	    GraphContr="GK107GLM"
	  ;;
	0x1003|0x1004|0x1005|0x1007|0x1008)
	    GraphContr="GK110"
	  ;;
	0x1001|0x100a|0x100c)
	    GraphContr="GK110B"
	  ;;
	0x1023|0x1024|0x1027|0x1029|0x102a|0x1023)
	    GraphContr="GK110BGL"
	  ;;
	0x101e|0x101f|0x1020|0x1021|0x1026|0x1028|0x102d|0x103a|0x103c)
	    GraphContr="GK110GL"
	  ;;
	0x1280|0x1281|0x1282|0x1284|0x1286|0x1287|0x1288|0x1289|0x128b|0x128d|0x12a0)
	    GraphContr="GK208"
	  ;;
	0x1290|0x1291|0x1292|0x1293|0x1294|0x1295|0x1296|0x1298|0x1299|0x129a)
	    GraphContr="GK208M"
	  ;;
	0x12b9|0x12ba)
	    GraphContr="GK208GLM"
	  ;;
	0x1380|0x1381|0x1382)
	    GraphContr="GM107"
	  ;;
	0x1390|0x1391|0x1392|0x1393|0x139a|0x139b|0x139c|0x139d)
	    GraphContr="GM107M"
	  ;;
	0x1389|0x13b9|0x13ba|0x13bb|0x13bc|0x13bd)
	    GraphContr="GM107GL"
	  ;;
	0x13b0|0x13b1|0x13b2|0x13b3|0x13b4|0x13b6)
	    GraphContr="GM107GLM"
	  ;;
	0x05e0|0x05e1|0x05e2|0x05e3|0x05e6|0x05ea|0x05eb|0x05f1|0x05f2)
	    GraphContr="GT200"
	  ;;
	0x05e7|0x05ed|0x05f8|0x05f9|0x05fd|0x05fe|0x05ff)
	    GraphContr="GT200GL"
	  ;;
	0x0ca0|0x0ca2|0x0ca3|0x0ca4|0x0ca5|0x0ca|0x0cac)
	    GraphContr="GT215"
	  ;;
	0x0ca8|0x0ca9|0x0caf|0x0cb0|0x0cb1)
	    GraphContr="GT215M"
	  ;;
	0x0cbc)
	    GraphContr="GT215GLM"
	  ;;
	0x0a20|0x0a22|0x0a23|0x0a6|0x0a7|0x0a30|0x0a32)
	    GraphContr="GT216"
	  ;;
	0x0a21|0x0a28|0x0a9|0x0a2a|0x0a2b|0x0a2c|0x0a2d|0x0a34|0x0a35)
	    GraphContr="GT216M"
	  ;;
	0x0a38)
	    GraphContr="GT216GL"
	  ;;
	0x0a3c)
	    GraphContr="GT216GLM"
	  ;;
	0x0a60|0x0a62|0x0a63|0x0a64|0x0a65|0x0a66|0x0a67|0x0a6f|0x0a76|0x0a7b|0x10c0|0x10c3|0x10c5|0x10d8)
	    GraphContr="GT218"
	  ;;
	0x0a68|0x0a69|0x0a6a|0x0a6c|0x0a6e|0x0a70|0x0a71|0x0a72|0x0a73|0x0a74|0x0a75|0x0a7a)
	    GraphContr="GT218M"
	  ;;
	0x0a78)
	    GraphContr="GT218GL"
	  ;;
	0x0a7c)
	    GraphContr="GT218GLM"
	  ;;
	0x0874|0x0876|0x087d|0x087e|0x087f)
	    GraphContr="ION"
	  ;;
	0x08a0|0x08a2|0x08a3|0x08a4|0x08a5)
	    GraphContr="MCP89"
	  ;;
	*)
	    KGraphDriver=
	    GraphContr="nVidia"
	    X11Driver="vesa"
	    MesaDriver=""
	  ;;
	esac
      ;;
    0x1106)
	    GraphContr="VIA"
	    X11Driver="vesa"
#	    X11Driver="via"
      ;;
    0x8086)
	KGraphDriver="i915"
	case "$device" in
	0x7121|0x7123|0x7125)
	    KGraphDriver="i810"
	    GraphContr="i810"
	    X11Driver="intel"
	    VideoRam="8192"
	  ;;
	0x1132)
	    KGraphDriver="i810"
	    GraphContr="i815"
	    X11Driver="intel"
	    VideoRam="8192"
	  ;;
	0x3577)
	    GraphContr="i830"
	    X11Driver="intel"
	    USE_915resolution="y"
	    KMS="y"
	    MesaDriver="i915"
	  ;;
	0x2562)
	    GraphContr="i845"
	    X11Driver="intel"
	    USE_915resolution="y"
	    KMS="y"
	    MesaDriver="i915"
	  ;;
	0x3582)
	    GraphContr="i855"
	    X11Driver="intel"
	    USE_915resolution="y"
	    KMS="y"
	    MesaDriver="i915"
	  ;;
	0x2572)
	    GraphContr="i865"
	    X11Driver="intel"
	    USE_915resolution="y"
	    KMS="y"
	    MesaDriver="i915"
	  ;;
	0x2582|0x2592)
	    GraphContr="i915"
	    X11Driver="intel"
	    USE_915resolution="y"
	    KMS="y"
	    MesaDriver="i915"
	  ;;
	0x2772|0x27a2|0x27ae)
	    GraphContr="i945"
	    X11Driver="intel"
	    USE_915resolution="y"
	    KMS="y"
	    MesaDriver="i915"
	  ;;
	0x29b2|0x29c2|0x29d2)
	    GraphContr="G33"
	    X11Driver="intel"
	    KMS="y"
	    MesaDriver="i915"
	  ;;
	0xa001|0xa011)
	    GraphContr="PINEVIEW"
	    X11Driver="intel"
	    KMS="y"
	    MesaDriver="i915"
	  ;;
	0x2972)
	    GraphContr="i946"
	    X11Driver="intel"
	    USE_915resolution="y"
	    KMS="y"
	  ;;
	0x2982|0x2992|0x29a2|0x2a02|0x2a12)
	    GraphContr="i965"
	    X11Driver="intel"
	    USE_915resolution="y"
	    KMS="y"
	    MesaDriver="i965"
	  ;;
	0x0042|0x0046)
	    GraphContr="HD Graphics"
	    X11Driver="intel"
	    KMS="y"
	    MesaDriver="i965"
	  ;;
	0x0102|0x0106|0x010a|0x0112|0x0116|0x0122|0x0126)
	    GraphContr="SANDYBRIDGE"
	    X11Driver="intel"
	    KMS="y"
	    MesaDriver="i965"
	  ;;
	0x0152|0x0156|0x015a|0x0162|0x0166|0x016a)
	    GraphContr="IVYBRIDGE"
	    X11Driver="intel"
	    KMS="y"
	    MesaDriver="i965"
	  ;;
	0x0402|0x0406|0x040a|0x0412|0x0416|0x041a|0x0422|0x0426|0x042a|0x0a02|0x0a06|0x0a0a|0x0a0e|0x0a12|0x0a16|0x0a1a|0x0a1e|0x0a22|0x0a26|0x0a2a)
	    GraphContr="HASWELL"
	    X11Driver="intel"
	    KMS="y"
	    MesaDriver="i965"
	  ;;
	0x0c02|0x0c06|0x0c0a|0x0c12|0x0c16|0x0c1a|0x0c22|0x0c26|0x0c2a|0x0d12|0x0d16|0x0d1a|0x0d22|0x0d26|0x0d2a|0x0d32|0x0d36|0x0d3a)
	    GraphContr="HASWELL"
	    X11Driver="intel"
	    KMS="y"
	    MesaDriver="i965"
	  ;;
	0x0d02|0x0d06|0x0d0a|0x0d0b|0x0d0e|0x0d12|0x0d16|0x0d1a|0x0d1b|0x0d1e|0x0d22|0x0d26|0x0d2a|0x0d2b|0x0d2e)
	    GraphContr="HASWELL"
	    X11Driver="intel"
	    KMS="y"
	    MesaDriver="i965"
	  ;;
	0x0f31|0x0f32|0x0f33|0x0157|0x0155)
	    GraphContr="Bay Trail"
	    X11Driver="intel"
	    KMS="y"
	    MesaDriver="i965"
	  ;;
	0x1602|0x1606|0x160a|0x160b|0x160d|0x160e)
	    GraphContr="Broadwell GT1"
	    X11Driver="intel"
	    KMS="y"
	    MesaDriver="i965"
	  ;;
	0x1612|0x1616|0x161a|0x161b|0x161d|0x161e)
	    GraphContr="Broadwell GT2"
	    X11Driver="intel"
	    KMS="y"
	    MesaDriver="i965"
	  ;;
	0x1622|0x1626|0x162a|0x162b|0x162d|0x162e)
	    GraphContr="Broadwell GT3"
	    X11Driver="intel"
	    KMS="y"
	    MesaDriver="i965"
	  ;;
	0x1902|0x1906|0x190A|0x190B|0x190E)
	    GraphContr="Skylake GT1"
	    X11Driver="intel"
	    KMS="y"
	    MesaDriver="i965"
	  ;;
	0x1912|0x1913|0x1915|0x1916|0x1917|0x191A|0x191B|0x191D|0x191E|0x1921)
	    GraphContr="Skylake GT2"
	    X11Driver="intel"
	    KMS="y"
	    MesaDriver="i965"
	  ;;
	0x1923|0x1926|0x1927|0x192B|0x192D)
	    GraphContr="Skylake GT3"
	    X11Driver="intel"
	    KMS="y"
	    MesaDriver="i965"
	  ;;
	0x192A|0x1932|0x193A|0x193B|0x193D)
	    GraphContr="Skylake GT4"
	    X11Driver="intel"
	    KMS="y"
	    MesaDriver="i965"
	  ;;
	0x22b0|0x22b1|0x22b2|0x22b3)
	    GraphContr="Cherryview"
	    X11Driver="intel"
	    KMS="y"
	    MesaDriver="i965"
	  ;;
	0x3e90|0x3e93|0x3e99|0x3e9c|0x3ea1|0x3ea4)
	    GraphContr="Coffeelake GT1"
	    X11Driver="intel"
	    KMS="y"
	    MesaDriver="i965"
	  ;;
	0x3e91|0x3e92|0x3e96|0x3e98|0x3e9a|0x3e9b|0x3e94|0x3ea9)
	    GraphContr="Coffeelake GT2"
	    X11Driver="intel"
	    KMS="y"
	    MesaDriver="i965"
	  ;;
	0x3ea5|0x3ea6|0x3ea7|0x3ea8|0x3e9a|0x3e9b|0x3e94|0x3ea9)
	    GraphContr="Coffeelake GT3"
	    X11Driver="intel"
	    KMS="y"
	    MesaDriver="i965"
	  ;;
	0x5902|0x5906|0x590a|0x5908|0x590b|0x590e)
	    GraphContr="Kaby Lake GT1"
	    X11Driver="intel"
	    KMS="y"
	    MesaDriver="i965"
	  ;;
	0x5913|0x5915)
	    GraphContr="Kaby Lake GT1.5"
	    X11Driver="intel"
	    KMS="y"
	    MesaDriver="i965"
	  ;;
	0x5912|0x5916|0x591a|0x591b|0x591d|0x591e|0x5921|0x591c|0x87c0)
	    GraphContr="Kaby Lake GT2"
	    X11Driver="intel"
	    KMS="y"
	    MesaDriver="i965"
	  ;;
	0x9b21|0x9ba0|0x9ba2|0x9ba4|0x9ba5|0x9ba8|0x9baa|0x9bab|0x9bac)
	    GraphContr="Comet Lake GT1"
	    X11Driver="intel"
	    KMS="y"
	    MesaDriver="i965"
	  ;;

	0x8108|0x8109)
	    KGraphDriver="gma500_gfx"
	    GraphContr="POULSBO"
	    X11Driver="fbdev"
	    KMS="y"
	  ;;
	0x4100|0x4101|0x4102|0x4103|0x4104|0x4105|0x4106|0x4107|0x4108)
	    KGraphDriver="gma500_gfx"
	    GraphContr="GMA600"
	    X11Driver="fbdev"
	    KMS="y"
	  ;;
	0x0130|0x0131|0x0132|0x0133|0x0134|0x0135|0x0136|0x0137)
	    KGraphDriver="gma500_gfx"
	    GraphContr="MEDFIELD"
	    X11Driver="fbdev"
	    KMS="y"
	  ;;
	0x0be0|0x0be1|0x0be2|0x0be3|0x0be4|0x0be5|0x0be6|0x0be7|0x0be8|0x0be9|0x0bea|0x0beb|0x0bec|0x0bee|0x0bef)
	    KGraphDriver="gma500_gfx"
	    GraphContr="GMA3600"
	    X11Driver="fbdev"
	    KMS="y"
	  ;;
	*)
	    KGraphDriver=
	    GraphContr="intel"
	    X11Driver="vesa"
	  ;;
	esac
      ;;
    esac
}

if [ -d /sys/bus/pci/devices ]; then
  for i in /sys/bus/pci/devices/*; do
#    echo $i
    if [ -f $i/class ] && [ -f $i/device ] && [ -f $i/vendor ]; then
      class=`cat $i/class`
      device=`cat $i/device`
      vendor=`cat $i/vendor`

      if [ -n $class ] && [ -n $device ] && [ -n $vendor ]; then

	case "$class" in
	0x03*)
	  if [ -z "$GraphContr" ]; then
	    chk_GraphicsController
	  fi
	  ;;
	esac

      fi

      if [ -n "$GraphContr" ]; then
	break
      fi
    fi
  done
fi

if [ -z "$GraphContr" ]; then
  GraphContr="Vesa"
  KMS="n"
fi
if [ -z "$X11Driver" ]; then
  X11Driver="vesa"
  KMS="n"
fi

if test x$VIDEOMOD = x"1"; then
  KMS="n"
fi

if test x$VIDEOMOD = x"2"; then
  X11Driver="vesa"
  KMS="n"
fi

#echo $GraphContr $X11Driver
if [ -n "$FIRMWARE" ]; then
  if [ x$KGraphDriver = x"radeon" ]; then
    if [ ! -d /lib/firmware/radeon ]; then
      if [ -f /mnt/firmware/$FIRMWARE.tar.xz ]; then
	mkdir -p /lib/firmware/radeon
	pushd /lib/firmware/radeon >/dev/null
	  tar -xaf /mnt/firmware/$FIRMWARE.tar.xz
	popd >/dev/null
      fi
    fi
  fi
fi

#if [ -f /mnt/firmware/modules/DRMPATH.txt ] && [ -n "$KGraphDriver" ] ; then
#  DRMPATH=`cat /mnt/firmware/modules/DRMPATH.txt`
#  if test -e $DRMPATH ; then
#    cp -a /mnt/firmware/modules/*.ko.xz $DRMPATH/
#    cp -ar /mnt/firmware/modules/ttm $DRMPATH/
#
#    if [ "$KGraphDriver" = "gma500_gfx" ]; then
#      cp -ar /mnt/firmware/modules/gma500 $DRMPATH/
#    fi
#    if [ "$KGraphDriver" = "i810" ]; then
#      cp -ar /mnt/firmware/modules/i810 $DRMPATH/
#    fi
#    if [ "$KGraphDriver" = "i915" ]; then
#      cp -ar /mnt/firmware/modules/i915 $DRMPATH/
#    fi
#    if [ "$KGraphDriver" = "nouveau" ]; then
#      cp -ar /mnt/firmware/modules/nouveau $DRMPATH/
#    fi
#    if [ "$KGraphDriver" = "radeon" ]; then
#      cp -ar /mnt/firmware/modules/radeon $DRMPATH/
#    fi
#    depmod
#  fi
#fi


if [ x$KMS = x"y" ]; then

  if [ x$KGraphDriver = x"i915" ]; then
    modprobe i915 modeset=1
    if [ $? != 0 ]; then
      X11Driver="vesa"
      KMS="n"
    fi
  fi

  if [ x$KGraphDriver = x"gma500_gfx" ]; then
    modprobe gma500_gfx
    if [ $? != 0 ]; then
      X11Driver="vesa"
      KMS="n"
    fi
  fi

  if [ x$KGraphDriver = x"radeon" ]; then
    modprobe radeon modeset=1 audio=1
    if [ $? != 0 ]; then
      X11Driver="vesa"
      KMS="n"
    fi
  fi

  if [ x$KGraphDriver = x"amdgpu" ]; then
    modprobe amdgpu audio=1
    if [ $? != 0 ]; then
      X11Driver="vesa"
      KMS="n"
    fi
  fi

  if [ x$KGraphDriver = x"nouveau" ]; then
    modprobe nouveau modeset=1
    if [ $? != 0 ]; then
      X11Driver="vesa"
      KMS="n"
    fi
  fi

else

  if [ x$KGraphDriver = x"i810" ]; then
    modprobe i810
    if [ $? != 0 ]; then
      X11Driver="vesa"
    fi
  fi

fi

echo "GraphContr=\"$GraphContr\"" >>$CfgFile
echo "X11Driver=\"$X11Driver\"" >>$CfgFile
echo "MesaDriver=\"$MesaDriver\"" >>$CfgFile
echo "KGraphDriver=\"$KGraphDriver\"" >>$CfgFile
echo "USE_915resolution=\"$USE_915resolution\"" >>$CfgFile
echo "KMS=\"$KMS\"" >>$CfgFile
echo "VideoRam=\"$VideoRam\"" >>$CfgFile
