LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File asusfan-0.1.patch of Package asusfan (Project openSUSE:Factory)

--- asusfan-0.1/cmd/main.c
+++ asusfan-0.1/cmd/main.c
@@ -38,9 +38,12 @@
   { "query", 0, 0, 'q' },
   { "temp", 1, 0, 't' },
   { "speeds", 1, 0, 'r' }, // Random short letter
+  { "debug", 0, 0, 'd' },
   { 0, 0, 0, 0 }
 };
 
+int debug = 0;
+
 int isnumber(const char* string) {
   char* temp;
   int i;
@@ -54,19 +57,22 @@
 
 int usage() {
   printf("AsusFan v%s (libasus v%s)\n\n", ASUSFAN_VERSION, LIBASUS_VERSION);
-  printf("Fan control for Asus V9999 series cards (and possibily other Asus Nvidia");
-  printf(" cards).\n\n");
+  printf("Fan control for Asus Nvidia-based graphics cards.\n\n");
   printf("Usage ./asusfan --query\n");
-  printf("Usage ./asusfan --mode=0 -speed=x\n");
+  printf("Usage ./asusfan --mode=0 --speed=x\n");
   printf("Usage ./asusfan --mode=1 [--temp=x:x:x:x] [--speeds=x:x:x:x:x]\n");
-  printf("Usage ./asusfan --mode=2\n\n");
-  printf("\t-m x, --mode=x\t0 for speed controlled, 2 for default speed\n");
-  printf("\t-s x, --speed=x\tSpeed in RPM, only useful with --mode=0\n");
+  printf("Usage ./asusfan --mode=2 --speed=x\n\n");
+  printf("\t-m x, --mode=x\t0 for fan speed mode, 1 for temperature mode,\n"
+         "\t              \t2 for manual mode\n");
+  printf("\t-s x, --speed=x\tSpeed in RPM (mode 0) or percent (mode 2)\n");
+  printf("\t               \tWARNING: Turning the fan of your graphics\n");
+  printf("\t               \tcard off or running it at low speeds can\n");
+  printf("\t               \tcause permanent damage to your hardware.\n");
   printf("\t-q, --query\tShow card vitals\n");
   printf("\t-h, --help\tThis screen\n\n");
   printf("\t-t x:x:x:x, --temp=x:x:x:x\n");
   printf("\t\tFour temperature boundaries for temperature controlled mode\n");
-  printf("\t-y x:x:x:x:, --speeds=x:x:x:x:x\n");
+  printf("\t-r x:x:x:x:, --speeds=x:x:x:x:x\n");
   printf("\t\tFive speed values, Fastest, Fast, Medium, Slow and Slowest.\n");
   printf("\t\tGiven in RPM and in the above order.\n\n");
   printf("Mode 1 defaults to:\n");
@@ -91,25 +97,13 @@
      { 3500, 3000, 2500, 2000, 1500 }
   };
 
-  int opt_speed = -1, opt_mode = -1;
-
-  if (libasus_init(0) == false) {
-    printf("ERROR: Could not initialise NVidia card\n");
-    return 1;
-  }
-
-  if ((result = libasus_detect(&i2cdev)) == false) {
-    printf("ERROR: Could not detect a suitable monitoring chip\n");
-    return 1;
-  }
+  int opt_speed = -1, opt_mode = -1, opt_query = 0;
 
   if (argc == 1) {
     return usage();
   }
 
-  libasus_create_card(&card, i2cdev, result);
-
-  while ((opt = getopt_long(argc, argv, "m:s:hq", long_options, NULL)) != -1) {
+  while ((opt = getopt_long(argc, argv, "m:s:hqtrd", long_options, NULL)) != -1) {
     switch (opt) {
       case 'm':
 	if (isnumber(optarg)) {
@@ -126,7 +120,7 @@
 	opt_speed = strtol(optarg, (char**)NULL, 10);
 	break;
       case 'q':
-	return query(card);
+        opt_query = 1;
 	break;
       case 'h':
 	return usage();
@@ -154,11 +148,28 @@
 	    return 1;
 	}
 	break;
+      case 'd':
+        debug = 1;
+        break;
       default:
 	return 1;
     }
   }
 
+  if (libasus_init(debug) == false) {
+    printf("ERROR: Could not initialise NVidia card\n");
+    return 1;
+  }
+
+  if ((result = libasus_detect(&i2cdev)) == false) {
+    printf("ERROR: Could not detect a suitable monitoring chip\n");
+    return 1;
+  }
+
+  libasus_create_card(&card, i2cdev, result);
+  
+  if (opt_query) return query(card);
+
   if ((opt_mode == 0) && (opt_speed > -1)) {
     libasus_set_gpu_fanspeed(card, opt_speed);
     libasus_set_gpu_fanmode(card, MODE_SPEED);
@@ -167,7 +178,7 @@
     libasus_set_gpu_fanmode(card, MODE_TEMP);
   } else if ((opt_mode == 2)) {
     libasus_set_gpu_fanmode(card, MODE_PWM);
-    libasus_set_gpu_pwmspeed(card, 0xff);
+    libasus_set_gpu_pwmspeed(card, opt_speed > -1 ? opt_speed : 100);
   } else {
     printf("Error: Illegal Parameter Values\n");
   }
@@ -186,10 +197,10 @@
 
   switch (libasus_get_gpu_fanmode(card)>>4) {
     case 0:
-      printf("Speed (RPM) by specified value\n");
+      printf("Fan Speed Mode\n");
       break;
     case 1:
-      printf("Temperature Controlled\n\n");
+      printf("Temperature Mode\n\n");
       libasus_get_gpu_tempctl(card, &temp_fan);
       printf("Current Settings:\n");
       printf("\tFastest: %dRPM\tBoundary 1:\t%dC\n",
@@ -204,7 +215,8 @@
 	temp_fan.speed[4]);
       break;
     case 2:
-      printf("Default Speed\n");
+      printf("Manual Mode\n\n");
+      printf("Current Fan Speed: %d%%\n",libasus_get_gpu_pwmspeed(card));
       break;
   }
   return 0;
--- asusfan-0.1/configure
+++ asusfan-0.1/configure
@@ -6202,7 +6202,7 @@
   exit 1
 fi
 gentoo_lt_version="1.5.10"
-gentoo_ltmain_version=`grep '^[:space:]*VERSION=' $ltmain | sed -e 's|^[:space:]*VERSION=||'`
+gentoo_ltmain_version=`grep '^[[:space:]]*VERSION=' $ltmain | sed -e 's|^[[:space:]]*VERSION=||'`
 if test "$gentoo_lt_version" != "$gentoo_ltmain_version"; then
   echo "$as_me:$LINENO: result: no" >&5
 echo "${ECHO_T}no" >&6
--- asusfan-0.1/libasus/detect.c
+++ asusfan-0.1/libasus/detect.c
@@ -25,11 +25,13 @@
   for (bus = 0; bus < 3; bus++) {
     for (dev = busses[bus]->FirstDev; dev; dev = dev->NextDev) {
       s = NULL;
+      dbg_printf("I2C device at address 0x%x\n",dev->SlaveAddr);
       switch (dev->SlaveAddr) {
 	case 0x98:
 	case 0x6e:
 	case 0xa0:
 	  break;
+        case 0x5a:
 	case 0x5c:
 	  if (f75375_detect(dev)) {
 	    *card = dev;
@@ -65,6 +67,7 @@
       card->get_gpu_tempctl = f75375_get_gpu_tempctl;
       card->set_gpu_tempctl = f75375_set_gpu_tempctl;
       card->set_gpu_pwmspeed = f75375_set_gpu_pwmspeed;
+      card->get_gpu_pwmspeed = f75375_get_gpu_pwmspeed;
       return true;
       break;
     default:
--- asusfan-0.1/libasus/f75375.c
+++ asusfan-0.1/libasus/f75375.c
@@ -8,16 +8,18 @@
   xf86I2CReadByte(dev, FINTEK_VENDOR1, &nvl);
   xf86I2CReadByte(dev, FINTEK_VENDOR2, &nvh);
 
-  if (MERGE_BYTE(nvh, nvl) != 0x3419) {
+  dbg_printf("f75375 vendor ID 0x%x\n",MERGE_BYTE(nvh,nvl));
+  if (MERGE_BYTE(nvh, nvl) != 0x3419) /* Fintek */
     return 0;
-  }
 
   xf86I2CReadByte(dev, ASUS_NV40_CHIPID_H, &nvh);
   xf86I2CReadByte(dev, ASUS_NV40_CHIPID_L, &nvl);
 
-  if (MERGE_BYTE(nvh, nvl) == 0x0306) {
+  dbg_printf("f75375 chip ID 0x%x\n",MERGE_BYTE(nvh,nvl));
+  if (MERGE_BYTE(nvh, nvl) == 0x0306 ||	/* F75375 */
+      MERGE_BYTE(nvh, nvl) == 0x0204)	/* similar chip in Asus V9570TD */
     return 1;
-  }
+
   return 0;
 }								
 
@@ -115,7 +117,17 @@
   return 0;
 }
 
-int f75375_set_gpu_pwmspeed(I2CDevPtr dev, I2CByte speed) {
+int f75375_set_gpu_pwmspeed(I2CDevPtr dev, int speed) {
+  speed = (speed << 8) / 100;
+  if (speed > 255) speed = 255;
+  
   xf86I2CWriteByte(dev, F75375S_FAN1_PWM, speed);
   return 0;
 }
+
+int f75375_get_gpu_pwmspeed(I2CDevPtr dev) {
+  I2CByte mode;
+  
+  xf86I2CReadByte(dev, F75375S_FAN1_PWM, &mode);
+  return (mode*100) >> 8;
+}
--- asusfan-0.1/libasus/f75375.h
+++ asusfan-0.1/libasus/f75375.h
@@ -8,9 +8,9 @@
 #include "xf86i2c.h"
 #include "i2c.h"
 
-int debug;
+extern int debug;
 
-#define dbg_printf(x) if (debug==1) printf(x)
+#define dbg_printf(x...) if (debug==1) printf(x)
 
 #define MODE_SPEED			0x00
 #define MODE_TEMP			0x10
@@ -25,7 +25,8 @@
 int f75375_set_gpu_fanspeed(I2CDevPtr dev, int desired_rpm);
 int f75375_get_gpu_fanmode(I2CDevPtr dev);
 int f75375_set_gpu_fanmode(I2CDevPtr dev, I2CByte mode);
-int f75375_set_gpu_pwmspeed(I2CDevPtr dev, I2CByte speed);
+int f75375_set_gpu_pwmspeed(I2CDevPtr dev, int speed);
+int f75375_get_gpu_pwmspeed(I2CDevPtr dev);
 int f75375_set_gpu_tempctl(I2CDevPtr dev, fan_vtemp speeds);
 int f75375_get_gpu_tempctl(I2CDevPtr dev, fan_vtemp *speeds);
 
--- asusfan-0.1/libasus/i2c.h
+++ asusfan-0.1/libasus/i2c.h
@@ -1,3 +1,6 @@
 #include "xf86i2c.h"
 
 extern I2CDevPtr gfxmon;
+
+I2CBusPtr I2cCreateBusPtr(char *name, int bus);
+
--- asusfan-0.1/libasus/libasus.c
+++ asusfan-0.1/libasus/libasus.c
@@ -6,8 +6,8 @@
 
   /* WARNING: This function no longer detects cards for you */
 
-  if (!init_nvclock()) return false;
-  if (!set_card(0)) return false;
+  if (!init_nvclock()) { printf("1\n"); return false; }
+  if (!set_card(0)) { printf("2\n"); return false; }
   NVLockUnlock(0);    // Unlock the CRTC registers
 
   return true;
@@ -37,10 +37,14 @@
   return card.set_gpu_fanmode(card.card, mode);
 }
 
-int libasus_set_gpu_pwmspeed(libasus_card card, I2CByte speed) {
+int libasus_set_gpu_pwmspeed(libasus_card card, int speed) {
   return card.set_gpu_pwmspeed(card.card, speed);
 }
 
+int libasus_get_gpu_pwmspeed(libasus_card card) {
+  return card.get_gpu_pwmspeed(card.card);
+}
+
 int libasus_set_gpu_tempctl(libasus_card card, fan_vtemp speeds) {
   return card.set_gpu_tempctl(card.card, speeds);
 }
--- asusfan-0.1/libasus/libasus.h
+++ asusfan-0.1/libasus/libasus.h
@@ -8,9 +8,9 @@
 #define true 	1
 #define false 	0
 
-int	debug;
+extern int	debug;
 
-#define dbg_printf(x) if (debug==1) printf(x)
+#define dbg_printf(x...) if (debug==1) printf(x)
 
 #define LIBASUS_DEVICE_F75375	0x01
 
@@ -37,7 +37,8 @@
 	int	(*set_gpu_fanmode)(I2CDevPtr dev, I2CByte mode);
 	int	(*get_gpu_tempctl)(I2CDevPtr dev, fan_vtemp *speeds);
 	int	(*set_gpu_tempctl)(I2CDevPtr dev, fan_vtemp speeds);
-	int	(*set_gpu_pwmspeed)(I2CDevPtr dev, I2CByte mode);
+	int	(*set_gpu_pwmspeed)(I2CDevPtr dev, int speed);
+	int	(*get_gpu_pwmspeed)(I2CDevPtr dev);
 } libasus_card;
 
 // Chip header files here
@@ -49,7 +50,8 @@
 int libasus_set_gpu_fanspeed(libasus_card card, int desired_rpm);
 int libasus_get_gpu_fanmode(libasus_card card);
 int libasus_set_gpu_fanmode(libasus_card card, I2CByte mode);
-int libasus_set_gpu_pwmspeed(libasus_card card, I2CByte speed);
+int libasus_set_gpu_pwmspeed(libasus_card card, int speed);
+int libasus_get_gpu_pwmspeed(libasus_card card);
 int libasus_set_gpu_tempctl(libasus_card card, fan_vtemp speeds);
 int libasus_get_gpu_tempctl(libasus_card card, fan_vtemp *speeds);
 
--- asusfan-0.1/libasus/libnvidia.c
+++ asusfan-0.1/libasus/libnvidia.c
@@ -70,7 +70,12 @@
 	  dbg_printf("Found some NV40 (6800) based card!\n");
           gfxcard.arch = NV40;
 	  break;
+        case 0x340:
+          dbg_printf("Found an NV30-based card\n");
+          gfxcard.arch = NV30;
+          break;
 	default:
+	  dbg_printf("Found an unknown card (device ID 0x%x)\n",gfxcard.device_id);
 	  return 0;
       }
       gfxcard.number = 0;