[Pommed-commits] r322 - in trunk/pommed: . pmac

Julien Blache jblache at alioth.debian.org
Sat May 5 17:03:36 UTC 2007


Author: jblache
Date: 2007-05-05 17:03:36 +0000 (Sat, 05 May 2007)
New Revision: 322

Modified:
   trunk/pommed/ambient.h
   trunk/pommed/pmac/ambient.c
   trunk/pommed/pmac/kbd_backlight.c
Log:
Share LMU information between kbd_backlight and ambient.


Modified: trunk/pommed/ambient.h
===================================================================
--- trunk/pommed/ambient.h	2007-05-05 16:44:26 UTC (rev 321)
+++ trunk/pommed/ambient.h	2007-05-05 17:03:36 UTC (rev 322)
@@ -5,12 +5,26 @@
 #ifndef __AMBIENT_H__
 #define __AMBIENT_H__
 
-
-#define KBD_AMBIENT_SENSOR      "/sys/devices/platform/applesmc/light"
 #define KBD_AMBIENT_MIN         0
 #define KBD_AMBIENT_MAX         255
 
+#ifndef __powerpc__
+# define KBD_AMBIENT_SENSOR      "/sys/devices/platform/applesmc/light"
+#else
+/* I2C ioctl */
+# define I2C_SLAVE           0x0703
 
+struct _lmu_info
+{
+  unsigned int lmuaddr;  /* i2c bus address */
+  char i2cdev[16];       /* i2c bus device */
+};
+
+extern struct _lmu_info lmu_info;
+
+#endif /* !__powerpc__ */
+
+
 struct _ambient_info
 {
   int left;

Modified: trunk/pommed/pmac/ambient.c
===================================================================
--- trunk/pommed/pmac/ambient.c	2007-05-05 16:44:26 UTC (rev 321)
+++ trunk/pommed/pmac/ambient.c	2007-05-05 17:03:36 UTC (rev 322)
@@ -40,9 +40,6 @@
 struct _ambient_info ambient_info;
 
 
-#define I2C_DEV	               "/dev/i2c-7"
-#define I2C_SLAVE              0x703
-#define LMU_ADDR               0x42
 #define KBD_AMBIENT_MAX_RAW    1600
 
 
@@ -53,7 +50,7 @@
   int ret;
   char buf[4];
 
-  fd = open(I2C_DEV, O_RDONLY);
+  fd = open(lmu_info.i2cdev, O_RDONLY);
   if (fd < 0)
     {
       *r = -1;
@@ -62,11 +59,11 @@
       ambient_info.right = 0;
       ambient_info.left = 0;
 
-      logmsg(LOG_ERR, "Could not open i2c device %s: %s\n",I2C_DEV, strerror(errno));
+      logmsg(LOG_ERR, "Could not open i2c device %s: %s\n", lmu_info.i2cdev, strerror(errno));
       return;
     }
 
-  ret = ioctl(fd, I2C_SLAVE, LMU_ADDR);
+  ret = ioctl(fd, I2C_SLAVE, lmu_info.lmuaddr);
   if (ret < 0)
     {
       close(fd);
@@ -77,7 +74,7 @@
       ambient_info.right = 0;
       ambient_info.left = 0;
 
-      logmsg(LOG_ERR, "ioctl failed on %s: %s\n",I2C_DEV, strerror(errno));
+      logmsg(LOG_ERR, "ioctl failed on %s: %s\n", lmu_info.i2cdev, strerror(errno));
 
       return;
     }

Modified: trunk/pommed/pmac/kbd_backlight.c
===================================================================
--- trunk/pommed/pmac/kbd_backlight.c	2007-05-05 16:44:26 UTC (rev 321)
+++ trunk/pommed/pmac/kbd_backlight.c	2007-05-05 17:03:36 UTC (rev 322)
@@ -47,23 +47,17 @@
 #include "../dbus.h"
 
 
-/* I2C ioctl */
-#define I2C_SLAVE           0x0703
-
 #define SYSFS_I2C_BASE      "/sys/class/i2c-dev"
 #define I2C_ADAPTER_NAME    "uni-n 0"
 
-#define ADB_DEVICE          "/dev/adb"
-#define ADB_BUFFER_SIZE     32
+# define ADB_DEVICE          "/dev/adb"
+# define ADB_BUFFER_SIZE     32
 
 
+struct _lmu_info lmu_info;
 struct _kbd_bck_info kbd_bck_info;
 
 
-static unsigned int lmuaddr;  /* i2c bus address */
-static char i2cdev[16]; /* i2c bus device */
-
-
 int
 has_kbd_backlight(void)
 {
@@ -102,7 +96,7 @@
   if (kbd_bck_info.inhibit ^ KBD_INHIBIT_CFG)
     return;
 
-  if (lmuaddr == 0)
+  if (lmu_info.lmuaddr == 0)
     return;
 
   curval = kbd_backlight_get();
@@ -113,15 +107,15 @@
   if ((val < KBD_BACKLIGHT_OFF) || (val > KBD_BACKLIGHT_MAX))
     return;
 
-  fd = open(i2cdev, O_RDWR);
+  fd = open(lmu_info.i2cdev, O_RDWR);
   if (fd < 0)
     {
-      logmsg(LOG_ERR, "Could not open %s: %s\n", i2cdev, strerror(errno));
+      logmsg(LOG_ERR, "Could not open %s: %s\n", lmu_info.i2cdev, strerror(errno));
 
       return;
     }
 
-  ret = ioctl(fd, I2C_SLAVE, lmuaddr);
+  ret = ioctl(fd, I2C_SLAVE, lmu_info.lmuaddr);
   if (ret < 0)
     {
       logmsg(LOG_ERR, "Could not ioctl the i2c bus: %s\n", strerror(errno));
@@ -368,7 +362,7 @@
 
   if ((!has_kbd_backlight()) || (ret < 0))
     {
-      lmuaddr = 0;
+      lmu_info.lmuaddr = 0;
 
       kbd_bck_info.r_sens = 0;
       kbd_bck_info.l_sens = 0;
@@ -458,8 +452,8 @@
   if (i2c_bus > 255)
     return -1;
 
-  ret = snprintf(i2cdev, sizeof(i2cdev) - 1, "/dev/i2c-%d", i2c_bus);
-  if ((ret < 0) || (ret >= (sizeof(i2cdev) - 1)))
+  ret = snprintf(lmu_info.i2cdev, sizeof(lmu_info.i2cdev) - 1, "/dev/i2c-%d", i2c_bus);
+  if ((ret < 0) || (ret >= (sizeof(lmu_info.i2cdev) - 1)))
     {
       logmsg(LOG_WARNING, "Error: i2c device path too long");
 
@@ -487,12 +481,12 @@
     }
 
   reg = of_find_property(node, "reg", &plen);
-  lmuaddr = (unsigned int) (*reg >> 1);
+  lmu_info.lmuaddr = (unsigned int) (*reg >> 1);
 
   free(reg);
   of_free_node(node);
 
-  logdebug("Found LMU controller at address 0x%x\n", lmuaddr);
+  logdebug("Found LMU controller at address 0x%x\n", lmu_info.lmuaddr);
 
   return 0;
 }
@@ -506,32 +500,24 @@
 
   ret = kbd_get_lmuaddr();
   if (ret < 0)
-    {
-      lmuaddr = 0;
+    return -1;
 
-      return -1;
-    }
-
   ret = kbd_get_i2cdev();
   if (ret < 0)
-    {
-      lmuaddr = 0;
+    return -1;
 
-      return -1;
-    }
-
-  fd = open(i2cdev, O_RDWR);
+  fd = open(lmu_info.i2cdev, O_RDWR);
   if (fd < 0)
     {
-      logmsg(LOG_WARNING, "Could not open device %s: %s\n", i2cdev, strerror(errno));
+      logmsg(LOG_WARNING, "Could not open device %s: %s\n", lmu_info.i2cdev, strerror(errno));
 
       return -1;
     }
 
-  ret = ioctl(fd, I2C_SLAVE, lmuaddr);
+  ret = ioctl(fd, I2C_SLAVE, lmu_info.lmuaddr);
   if (ret < 0)
     {
-      logmsg(LOG_ERR, "ioctl failed on %s: %s\n", i2cdev, strerror(errno));
+      logmsg(LOG_ERR, "ioctl failed on %s: %s\n", lmu_info.i2cdev, strerror(errno));
 
       close(fd);
       return -1;
@@ -540,14 +526,14 @@
   ret = read(fd, buffer, 4);
   if (ret != 4)
     {
-      logmsg(LOG_WARNING, "Probing failed on %s: %s\n", i2cdev, strerror(errno));
+      logmsg(LOG_WARNING, "Probing failed on %s: %s\n", lmu_info.i2cdev, strerror(errno));
 
       close(fd);
       return -1;
     }
   close(fd);
 
-  logdebug("Probing successful on %s\n", i2cdev);
+  logdebug("Probing successful on %s\n", lmu_info.i2cdev);
 
   return 0;
 }




More information about the Pommed-commits mailing list