[Pommed-commits] r323 - in trunk/pommed: . pmac
Julien Blache
jblache at alioth.debian.org
Sun May 6 10:09:25 UTC 2007
Author: jblache
Date: 2007-05-06 10:09:24 +0000 (Sun, 06 May 2007)
New Revision: 323
Modified:
trunk/pommed/ambient.h
trunk/pommed/pmac/ambient.c
trunk/pommed/pmac/kbd_backlight.c
Log:
Add PMU05 ambient sensors support.
Modified: trunk/pommed/ambient.h
===================================================================
--- trunk/pommed/ambient.h 2007-05-05 17:03:36 UTC (rev 322)
+++ trunk/pommed/ambient.h 2007-05-06 10:09:24 UTC (rev 323)
@@ -14,6 +14,9 @@
/* I2C ioctl */
# define I2C_SLAVE 0x0703
+# define ADB_DEVICE "/dev/adb"
+# define ADB_BUFFER_SIZE 32
+
struct _lmu_info
{
unsigned int lmuaddr; /* i2c bus address */
Modified: trunk/pommed/pmac/ambient.c
===================================================================
--- trunk/pommed/pmac/ambient.c 2007-05-05 17:03:36 UTC (rev 322)
+++ trunk/pommed/pmac/ambient.c 2007-05-06 10:09:24 UTC (rev 323)
@@ -32,6 +32,8 @@
#include <syslog.h>
#include <sys/ioctl.h>
+#include <linux/adb.h>
+
#include "../pommed.h"
#include "../ambient.h"
#include "../dbus.h"
@@ -40,11 +42,13 @@
struct _ambient_info ambient_info;
-#define KBD_AMBIENT_MAX_RAW 1600
+#define LMU_AMBIENT_MAX_RAW 1600
+#define PMU_AMBIENT_MAX_RAW 2048
-void
-ambient_get(int *r, int *l)
+
+static void
+lmu_ambient_get(int *r, int *l)
{
int fd;
int ret;
@@ -95,8 +99,8 @@
close(fd);
/* found in pbbuttonsd.conf */
- *r = (int) (((buf[0] << 8) | buf[1]) * KBD_AMBIENT_MAX) / KBD_AMBIENT_MAX_RAW;
- *l = (int) (((buf[2] << 8) | buf[3]) * KBD_AMBIENT_MAX) / KBD_AMBIENT_MAX_RAW;
+ *r = (int) (((buf[0] << 8) | buf[1]) * KBD_AMBIENT_MAX) / LMU_AMBIENT_MAX_RAW;
+ *l = (int) (((buf[2] << 8) | buf[3]) * KBD_AMBIENT_MAX) / LMU_AMBIENT_MAX_RAW;
logdebug("Ambient light: right %d, left %d\n", *r, *l);
@@ -104,8 +108,86 @@
ambient_info.left = *l;
}
+static void
+pmu_ambient_get(int *r, int *l)
+{
+ int fd;
+ int ret;
+ char buf[ADB_BUFFER_SIZE];
+ fd = open(ADB_DEVICE, O_RDWR);
+ if (fd < 0)
+ {
+ *r = -1;
+ *l = -1;
+
+ ambient_info.right = 0;
+ ambient_info.left = 0;
+
+ logmsg(LOG_ERR, "Could not open ADB device %s: %s\n", ADB_DEVICE, strerror(errno));
+ return;
+ }
+
+ buf[0] = PMU_PACKET;
+ buf[1] = 0x4f; /* PMU command */
+ buf[2] = 1;
+
+ ret = write(fd, buf, 3);
+ if (ret != 3)
+ {
+ *r = -1;
+ *l = -1;
+
+ ambient_info.right = 0;
+ ambient_info.left = 0;
+
+ logmsg(LOG_ERR, "Could not send PMU command: %s\n", strerror(errno));
+ close(fd);
+ return;
+ }
+
+ ret = read(fd, buf, ADB_BUFFER_SIZE);
+ if (ret != 5)
+ {
+ *r = -1;
+ *l = -1;
+
+ ambient_info.right = 0;
+ ambient_info.left = 0;
+
+ logmsg(LOG_ERR, "Could not read PMU reply: %s\n", strerror(errno));
+ close(fd);
+ return;
+ }
+
+ close(fd);
+
+ /* Taken from pbbuttonsd */
+ *l = (int) (((buf[2] << 8) | buf[1]) * KBD_AMBIENT_MAX) / PMU_AMBIENT_MAX_RAW;
+ *r = (int) (((buf[4] << 8) | buf[3]) * KBD_AMBIENT_MAX) / PMU_AMBIENT_MAX_RAW;
+
+ logdebug("Ambient light: right %d, left %d\n", *r, *l);
+
+ ambient_info.right = *r;
+ ambient_info.left = *l;
+}
+
void
+ambient_get(int *r, int *l)
+{
+ if ((mops->type == MACHINE_POWERBOOK_58)
+ || (mops->type == MACHINE_POWERBOOK_59))
+ {
+ pmu_ambient_get(r, l);
+ }
+ else
+ {
+ lmu_ambient_get(r, l);
+ }
+}
+
+
+void
ambient_init(int *r, int *l)
{
ambient_get(r, l);
Modified: trunk/pommed/pmac/kbd_backlight.c
===================================================================
--- trunk/pommed/pmac/kbd_backlight.c 2007-05-05 17:03:36 UTC (rev 322)
+++ trunk/pommed/pmac/kbd_backlight.c 2007-05-06 10:09:24 UTC (rev 323)
@@ -50,10 +50,7 @@
#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 _lmu_info lmu_info;
struct _kbd_bck_info kbd_bck_info;
More information about the Pommed-commits
mailing list