158bba96d80903f54857dd30e34cd4d260e4f75e
[profile/ivi/intel-emgd-kmod.git] / service / intel-emgd-kmod.init
1 #!/bin/bash
2
3 ######################################################################
4 #
5 #        Russellville  CrownBay    CrossvilleOKI   ML7213    NexCom
6 #monitor LVDS 7        LVDS 13     LVDS 7          LVDS 13   LVDS 7
7 #Gfx     8086:8108     8086:4108   8086:4108       8086:4108 8086:4108
8 #
9 ######################################################################
10 #
11 #       unknown
12 # 1     Russellville                    DEVICE has 8086:8108
13 # 2     CrownBay                        VENDOR !has 10db && DEVICE has 8086:4108
14 # 3     CrossvilleOKI                   VENDOR has 10db && DEVICE has 8086:4108
15
16 PATH=$PATH:/bin:/sbin:/usr/bin
17 DEVICE_LSPCI=`lspci -n | cut -d$' ' -f3 -s`
18
19 find_board_type() {
20         local __resultvar=$1
21         local _board_type="unknown"
22         local IS_8108='0'
23         local IS_4108='0'
24         local IS_ML7213='0'
25         local IS_CROWNBAY='0'
26         local oldIFS=$IFS
27         #set -x
28         for entry in $DEVICE_LSPCI; do
29                 #echo $entry
30                 IFS=$':'
31                 set -- $entry
32
33                 VENDOR=`echo $1`
34                 DEVICE=`echo $2`
35                 if [ $VENDOR == '8086' ]; then
36                         if [ $DEVICE == '8108' ]; then 
37                                 IS_8108='1'
38                                 break
39                         elif [ $DEVICE == '4108' ]; then
40                                 IS_4108='1'
41                         fi
42                 elif [ $VENDOR == '10db' ]; then
43                         IS_ML7213='1'
44                 elif [ $VENDOR == '12d8' ]; then
45                         IS_CROWNBAY='1'
46                 fi
47                 IFS=$oldIFS
48         done
49
50         if [ $IS_8108 == '1' ]; then
51                 _board_type='Russellville'
52         elif [ $IS_4108 == '1' ]; then
53                 if [ $IS_ML7213 == '1' ]; then
54                         _board_type='CrossvilleOKI'
55                 elif [ $IS_CROWNBAY == '1' ]; then
56                         _board_type='CrownBay'
57                 else
58                         _board_type='NexCom'
59                 fi
60         else
61                 _board_type='unknown'
62         fi
63
64         # This logic is stupid and the reliable method is to query the firmware interface, which now is not available yet.
65
66         echo "$_board_type"
67 }
68
69 platform="unknown"
70 set_config() {
71         IS_EMGD_NEEDED=0
72         for entry in $DEVICE_LSPCI; do
73                 VENDOR_ID=0x`echo $entry | cut -d':' -f1`
74                 DEVICE_ID=0x`echo $entry | cut -d':' -f2`
75                 if [[ $VENDOR_ID -eq 0x8086 ]]; then
76                         case $DEVICE_ID in
77                                 0x410[8-f] | 0x8108 | 0x8182 )
78                                         # This should cover all Intel Poulsbo and E6xx (Tunnel Creek) graphics core
79                                         echo "Found a Graphics core supported by EMGD: $entry"
80                                         IS_EMGD_NEEDED=1
81                                         ;;
82                         esac
83                 fi
84         done
85
86         if [[ $IS_EMGD_NEEDED -ne 0 ]]; then
87                 IS_CONFIGID_SET=`modprobe -c | grep 'option emgd' | grep configid -c`
88                 if [[ $IS_CONFIGID_SET -eq 0 ]]; then
89                         # Trying to get a good value by default based on board type
90                         boardname=`find_board_type $platform`
91                         configid=0
92                         if [ $boardname == 'NexCom' ];
93                         then
94                                 configid=3
95                         elif [ $boardname == 'CrownBay' ];
96                         then
97                                 configid=2
98                         elif [ $boardname == 'Russellville' ] || [ $boardname == 'CrossvilleOKI' ];
99                         then
100                                 configid=1
101                         fi
102
103                         if [ $boardname != 'unknown' ];
104                         then
105                                 echo "Boardname is $boardname, configid=$configid"
106                                 modprobe emgd configid=$configid
107                         else
108                                 echo "Could not determine what board we are running on, please set configid manually"
109                         fi
110                 else
111                         # There is a specific configuration given in /etc/modprobe.d/, use that one
112                         echo "configid parameter set by user (via /etc/modprobe.d/)"
113                         modprobe emgd
114                 fi
115
116                 # If an appropriate weston configuration file has not been created then create it
117                 if [ ! -f /root/.config/weston.ini ]; then
118                         mkdir -p /root/.config
119                         cat > /root/.config/weston.ini <<EOF
120 [shell]
121 type=desktop-shell.so
122 locking=false
123
124 [launcher]
125 icon=/usr/share/weston/terminal.png
126 path=/usr/bin/weston-terminal
127
128 [output]
129 name=LVDS1
130 mode= 60.00 800 864 976 1088 480 486 494 517 -hsync +vsync ==
131
132 EOF
133                 fi
134         fi
135 }
136
137 set_config
138 exit $?