summaryrefslogtreecommitdiff
path: root/mdm/distro/debian-lenny/discover-devices.patch
blob: 23a7f2877251aa60037cb061389dc73e2adc69c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
diff -Nru tree/usr/sbin/discover-devices debian-lenny-tree/usr/sbin/discover-devices
--- tree/usr/sbin/discover-devices	2008-09-12 08:48:06.000000000 -0300
+++ debian-lenny-tree/usr/sbin/discover-devices	2008-09-12 08:50:37.000000000 -0300
@@ -25,8 +25,6 @@
 
 # TODO: find a decent way to do all this.
 
-DISCOVER=/sbin/discover
-
 # This function prints the physical addresses of the mice found
 function discover_input () {
 
@@ -48,29 +46,16 @@
 # Prints bus address and drivers of the video cards.
 function video_cards () {
 
-    # calling discover is way toooooo slow!
-    OUTPUT=$($DISCOVER -t display --vendor-id --model-id)
-    VENDOR_IDS=($(echo "$OUTPUT" | cut -d' ' -f1))
-    MODEL_IDS=($( echo "$OUTPUT" | cut -d' ' -f2))
-    # There can be empty lines on "drivers"
-    DRIVERS=($($DISCOVER -t display --data-path=xfree86/server/device/driver \
-	       | sed 's/^$/vesa/g'))
-
-    for (( i = 0; i < ${#VENDOR_IDS[@]}; i++)); do
-        # If there are multiple cards with the same IDs, lspci will print
-	# multiple lines
-
-	# See how many times we already used these IDs:
-	TIMES_USED=0
-	for (( j=0; j < i; j++)); do
-	    if ( [ "${VENDOR_IDS[j]}" = "${VENDOR_IDS[i]}" ] &&
-	         [ "${MODEL_IDS[j]}"  = "${MODEL_IDS[i]}"  ] ); then
-		 TIMES_USED=$((TIMES_USED+1))
-	    fi
-	done
+    IDS_BY_DRIVER=/usr/share/xserver-xorg/pci
+
+    # 'discover' prints in the reverse order of lspci, I think
+    BUS_IDS=($(lspci | grep VGA | cut -d' ' -f1 | tac))
 
-	BUS_IDS[i]=$(lspci -d ${VENDOR_IDS[i]}:${MODEL_IDS[i]} | 
-		     cut -d' ' -f1 | head -n $((TIMES_USED+1)) | tail -n 1)
+    for (( i=0; i < ${#BUS_IDS[@]}; i++ )); do
+        PCI_DEVICE=$(lspci -n -s ${BUS_IDS[i]} | cut -d' ' -f3)
+        # We might find multiple drivers. Use the first.
+        DRIVERS[i]=$(grep -i ${PCI_DEVICE/:/} $IDS_BY_DRIVER/* | \
+                     cut -d'/' -f6 | cut -d'.' -f1 | head -n 1)
     done
 
     for (( i=0 ; i < ${#BUS_IDS[@]}; i++ )) ; do
@@ -78,17 +63,19 @@
         # below we split in 00 and 00.00
         NUMS=(`echo ${BUS_IDS[$i]} |  \
               awk 'BEGIN {FS=":"}{print toupper($1), toupper($2)}'`)
-	# now, we split 00.00 in 00 and 00
+        # now, we split 00.00 in 00 and 00
         SEC_NUMS=(`echo ${NUMS[1]} |  \
                   awk 'BEGIN {FS="."}{print toupper($1), toupper($2)}'`)
-	# now, we convert the numbers from hexa to decimal base 
+        # now, we convert the numbers from hexa to decimal base
         echo -e "bus\t`echo "obase=10;ibase=16;${NUMS[0]};${SEC_NUMS[0]};${SEC_NUMS[1]};" | bc | paste -s -d":"`"
 
     done
-    
+
     for i in ${DRIVERS[@]}; do
         echo -e "driver\t$i"
     done
+
+
 } # video_cards
 
 # ******************** MAIN *************************