Gaudenz Steinlin <[EMAIL PROTECTED]> wrote:

Hi,

>> Can you please send me a (bzip2'ed) tarball of /proc/device-tree ?
>
> OK, It's attached. 

Can you please try the attached patch, on top of the current SVN ?

Thanks,

JB.

-- 
 Julien BLACHE - Debian & GNU/Linux Developer - <[EMAIL PROTECTED]> 
 
 Public key available on <http://www.jblache.org> - KeyID: F5D6 5169 
 GPG Fingerprint : 935A 79F1 C8B3 3521 FD62 7CC7 CD61 4FD7 F5D6 5169 

Index: pmac/kbd_backlight.c
===================================================================
--- pmac/kbd_backlight.c	(revision 319)
+++ pmac/kbd_backlight.c	(working copy)
@@ -36,6 +36,8 @@
 #include <sys/ioctl.h>
 #include <linux/i2c.h>
 
+#include <linux/adb.h>
+
 #include <ofapi/of_api.h>
 
 #include "../pommed.h"
@@ -51,7 +53,10 @@
 #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
 
+
 struct _kbd_bck_info kbd_bck_info;
 
 
@@ -76,14 +81,12 @@
 static int
 kbd_backlight_get(void)
 {
-  if (lmuaddr == 0)
-    return 0;
-
   return kbd_bck_info.level;
 }
 
+
 static void
-kbd_backlight_set(int val, int who)
+kbd_lmu_backlight_set(int val, int who)
 {
   int curval;
 
@@ -147,7 +150,7 @@
 
 	  if (write (fd, buf, 3) < 0)
 	    {
-	      logmsg(LOG_ERR, "Could not set kbd brightness: %s\n", strerror(errno));
+	      logmsg(LOG_ERR, "Could not set LMU kbd brightness: %s\n", strerror(errno));
 
 	      continue;
 	    }
@@ -170,7 +173,7 @@
   buf[2] = (unsigned char) val << 4;
 
   if (write (fd, buf, 3) < 0)
-    logmsg(LOG_ERR, "Could not set kbd brightness: %s\n", strerror(errno));
+    logmsg(LOG_ERR, "Could not set LMU kbd brightness: %s\n", strerror(errno));
 
   close(fd);
 
@@ -179,6 +182,119 @@
   kbd_bck_info.level = val;
 }
 
+static void
+kbd_pmu_backlight_set(int val, int who)
+{
+  int curval;
+
+  int i;
+  float fadeval;
+  float step;
+  struct timespec fade_step;
+
+  int fd;
+  int ret;
+  unsigned char buf[ADB_BUFFER_SIZE];
+
+  if (kbd_bck_info.inhibit ^ KBD_INHIBIT_CFG)
+    return;
+
+  curval = kbd_backlight_get();
+
+  if (val == curval)
+    return;
+
+  if ((val < KBD_BACKLIGHT_OFF) || (val > KBD_BACKLIGHT_MAX))
+    return;
+
+  fd = open(ADB_DEVICE, O_RDWR);
+  if (fd < 0)
+    {
+      logmsg(LOG_ERR, "Could not open %s: %s\n", ADB_DEVICE, strerror(errno));
+
+      return;
+    }
+
+  if (who == KBD_AUTO)
+    {
+      fade_step.tv_sec = 0;
+      fade_step.tv_nsec = (KBD_BACKLIGHT_FADE_LENGTH / KBD_BACKLIGHT_FADE_STEPS) * 1000000;
+
+      fadeval = (float)curval;
+      step = (float)(val - curval) / (float)KBD_BACKLIGHT_FADE_STEPS;
+
+      for (i = 0; i < KBD_BACKLIGHT_FADE_STEPS; i++)
+	{
+	  fadeval += step;
+
+	  buf[0] = PMU_PACKET;
+	  buf[1] = 0x4f; /* PMU command */
+	  buf[2] = 0;
+	  buf[3] = 0;
+	  buf[4] = (unsigned char)fadeval;
+
+	  ret = write(fd, buf, 5);
+	  if (ret != 5)
+	    {
+	      logmsg(LOG_ERR, "Could not set PMU kbd brightness: %s\n", strerror(errno));
+
+	      continue;
+	    }
+
+	  ret = read(fd, buf, ADB_BUFFER_SIZE);
+	  if (ret < 0)
+	    {
+	      logmsg(LOG_ERR, "Could not read PMU reply: %s\n", strerror(errno));
+
+	      continue;
+	    }
+
+	  logdebug("KBD backlight value faded to %d\n", (int)fadeval);
+
+	  nanosleep(&fade_step, NULL);
+	}
+    }
+  
+  buf[0] = PMU_PACKET;
+  buf[1] = 0x4f; /* PMU command */
+  buf[2] = 0;
+  buf[3] = 0;
+  buf[4] = val;
+
+  ret = write(fd, buf, 5);
+  if (ret != 5)
+    {
+      logmsg(LOG_ERR, "Could not set PMU kbd brightness: %s\n", strerror(errno));
+    }
+  else
+    {
+      ret = read(fd, buf, ADB_BUFFER_SIZE);
+      if (ret < 0)
+	logmsg(LOG_ERR, "Could not read PMU reply: %s\n", strerror(errno));
+    }
+
+  close(fd);
+
+  mbpdbus_send_kbd_backlight(val, kbd_bck_info.level, who);
+
+  kbd_bck_info.level = val;
+}
+
+static void
+kbd_backlight_set(int val, int who)
+{
+  if ((mops->type == MACHINE_POWERBOOK_58)
+      || (mops->type == MACHINE_POWERBOOK_59))
+    {
+      kbd_pmu_backlight_set(val, who);
+    }
+  else
+    {
+      kbd_lmu_backlight_set(val, who);
+    }
+}
+
+
 void
 kbd_backlight_step(int dir)
 {
@@ -244,7 +360,14 @@
 
   kbd_bck_info.auto_on = 0;
 
-  ret = kbd_probe_lmu();
+  if ((mops->type == MACHINE_POWERBOOK_58)
+      || (mops->type == MACHINE_POWERBOOK_59))
+    {
+      /* Nothing to probe for the PMU05 machines */
+      ret = 0;
+    }
+  else
+    ret = kbd_probe_lmu();
 
   if ((!has_kbd_backlight()) || (ret < 0))
     {
@@ -360,8 +483,12 @@
 
   node = of_find_node_by_type("lmu-controller", 0);
   if (node == NULL)
-    return -1;
+    {
+      logmsg(LOG_ERR, "Error: no lmu-controller found in device-tree");
 
+      return -1;
+    }
+
   reg = of_find_property(node, "reg", &plen);
   lmuaddr = (unsigned int) (*reg >> 1);
 

Reply via email to