summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichel Dänzer <michel@tungstengraphics.com>2007-10-13 18:56:43 +0200
committerMichel Dänzer <michel@tungstengraphics.com>2007-10-13 18:58:21 +0200
commitfd5bb7bb5e968127b87102320eccc1222f205e5a (patch)
tree551fc32c2d20c7672c71cc96c4856587a4d9e191
parentfbf121add5584049627f07345fc502b2aefc88ce (diff)
radeon: Improve detection of default value for Option "MacModel" on Linux.
* Detect all PowerBooks with dual link DVI (according to developer.apple.com) and both Mac Mini G4 models. Other PowerBooks and iBooks should be covered by the 'detected as' line in /proc/cpuinfo. * Give specific instructions for overriding and reporting incorrect detection. * Only perform detection when Option "MacModel" isn't present with a valid value. * Close /proc/cpuinfo file handle when done with it. * Coding style cleanups.
-rw-r--r--src/radeon_output.c101
1 files changed, 67 insertions, 34 deletions
diff --git a/src/radeon_output.c b/src/radeon_output.c
index 0325d848..a5b13932 100644
--- a/src/radeon_output.c
+++ b/src/radeon_output.c
@@ -2832,42 +2832,76 @@ static void RADEONSetupGenericConnectors(ScrnInfoPtr pScrn)
}
#if defined(__powerpc__)
+
/*
* Returns RADEONMacModel or 0 based on lines 'detected as' and 'machine'
- * in /proc/cpuinfo file */
-static RADEONMacModel getMacModel (void){
- RADEONMacModel dviConn = 0;
- int macmodel = 0;
- char cpuline[50]; /* 50 should be sufficient for /proc/cpuinfo lines */
+ * in /proc/cpuinfo (on Linux) */
+static RADEONMacModel RADEONDetectMacModel(ScrnInfoPtr pScrn)
+{
+ RADEONMacModel ret = 0;
+#ifdef __linux__
+ char cpuline[50]; /* 50 should be sufficient for our purposes */
FILE *f = fopen ("/proc/cpuinfo", "r");
- if (f != NULL){
- while (fgets (cpuline, sizeof cpuline, f)){
- char *start;
- if (!strncmp (cpuline, "machine", strlen ("machine"))){
- if ((start = strstr (cpuline, "PowerBook")) != NULL)
- macmodel = *(start + strlen ("PowerBook")) - '0';
- /* macmodel cannot be used here, because 'machine' line arrives before 'detected as' line */
- }else if (!strncmp (cpuline, "detected as", strlen ("detected as"))){
- if (strstr (cpuline, "iBook"))
- dviConn = RADEON_MAC_IBOOK;
- else if (strstr (cpuline, "PowerBook")){
- /* database with known DVI connectors:
- * dualllink: 5,2
- * singlelink: */
- if (macmodel >= 5)
- dviConn = RADEON_MAC_POWERBOOK_DL;
- else
- dviConn = RADEON_MAC_POWERBOOK;
+
+ if (f != NULL) {
+ while (fgets(cpuline, sizeof cpuline, f)) {
+ if (!strncmp(cpuline, "machine", strlen ("machine"))) {
+ if (strstr(cpuline, "PowerBook5,6") ||
+ strstr(cpuline, "PowerBook5,7") ||
+ strstr(cpuline, "PowerBook5,8") ||
+ strstr(cpuline, "PowerBook5,9")) {
+ ret = RADEON_MAC_POWERBOOK_DL;
+ break;
+ }
+
+ if (strstr(cpuline, "PowerMac10,1") ||
+ strstr(cpuline, "PowerMac10,2")) {
+ ret = RADEON_MAC_MINI;
+ break;
+ }
+ } else if (!strncmp(cpuline, "detected as", strlen("detected as"))) {
+ if (strstr(cpuline, "iBook")) {
+ ret = RADEON_MAC_IBOOK;
+ break;
+ } else if (strstr(cpuline, "PowerBook")) {
+ ret = RADEON_MAC_POWERBOOK_DL;
+ break;
}
- /* else: 'detected as' line not found, we suppose not apple PowerPC computer, so nothing to do */
+
+ /* No known PowerMac model detected */
break;
}
}
- }else
- xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Cannot detect laptop model for DVI connector identification because /proc/cpuinfo not readable. Please use the MacModel option in xorg.conf to configure it.\n");
- return dviConn;
-}
+
+ fclose (f);
+ } else
+ xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
+ "Cannot detect PowerMac model because /proc/cpuinfo not "
+ "readable.\n");
+
+#endif /* __linux */
+
+ if (ret) {
+ xf86DrvMsg(pScrn->scrnIndex, X_DEFAULT, "Detected %s.\n",
+ ret == RADEON_MAC_POWERBOOK_DL ? "PowerBook with dual link DVI" :
+ ret == RADEON_MAC_POWERBOOK ? "PowerBook with single link DVI" :
+ ret == RADEON_MAC_IBOOK ? "iBook" :
+ "Mac Mini");
+ xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+ "If this is not correct, try Option \"MacModel\" and "
+ "consider reporting to the\n");
+ xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+ "xorg-driver-ati@lists.x.org mailing list"
+#ifdef __linux__
+ " with the contents of /proc/cpuinfo"
#endif
+ ".\n");
+ }
+
+ return ret;
+}
+
+#endif /* __powerpc__ */
/*
* initialise the static data sos we don't have to re-do at randr change */
@@ -2894,11 +2928,7 @@ Bool RADEONSetupConnectors(ScrnInfoPtr pScrn)
}
#if defined(__powerpc__)
- info->MacModel = getMacModel ();
- if (info->MacModel)
- xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Detected DVI connector %d.\n", info->MacModel);
-
- /* overwrite detected data, in case it's falsely detected */
+ info->MacModel = 0;
optstr = (char *)xf86GetOptValString(info->Options, OPTION_MAC_MODEL);
if (optstr) {
if (!strncmp("ibook", optstr, strlen("ibook")))
@@ -2911,10 +2941,13 @@ Bool RADEONSetupConnectors(ScrnInfoPtr pScrn)
info->MacModel = RADEON_MAC_MINI;
else {
xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Invalid Mac Model: %s\n", optstr);
- return FALSE;
}
}
+ if (!info->MacModel) {
+ info->MacModel = RADEONDetectMacModel(pScrn);
+ }
+
if (info->MacModel){
if (!RADEONSetupAppleConnectors(pScrn))
RADEONSetupGenericConnectors(pScrn);