[Pommed-commits] r256 - in trunk/pommed: . pmac
Julien Blache
jblache at alioth.debian.org
Wed Feb 21 21:43:19 CET 2007
Author: jblache
Date: 2007-02-21 21:43:19 +0100 (Wed, 21 Feb 2007)
New Revision: 256
Added:
trunk/pommed/pmac/sysfs_backlight.c
Removed:
trunk/pommed/pmac/r9600_backlight.c
Modified:
trunk/pommed/Makefile
trunk/pommed/lcd_backlight.h
trunk/pommed/pommed.c
Log:
Turn r9600_backlight.c into a more generic sysfs backlight driver.
Modified: trunk/pommed/Makefile
===================================================================
--- trunk/pommed/Makefile 2007-02-10 19:10:31 UTC (rev 255)
+++ trunk/pommed/Makefile 2007-02-21 20:43:19 UTC (rev 256)
@@ -17,7 +17,7 @@
LDFLAGS = -lz $(CONFUSE_LIBS) $(DBUS_LIBS) $(ALSA_LIBS)
SOURCES = pommed.c cd_eject.c evdev.c conffile.c audio.c dbus.c \
- pmac/r9600_backlight.c pmac/r128_backlight.c \
+ pmac/sysfs_backlight.c pmac/r128_backlight.c \
pmac/kbd_backlight.c pmac/ambient.c
OF_SOURCES = pmac/oflib/of_externals.c pmac/oflib/of_internals.c \
@@ -59,7 +59,7 @@
# PowerMac-specific files
pmac/kbd_backlight.o: pmac/kbd_backlight.c kbd_backlight.h pommed.h ambient.h conffile.h dbus.h
-pmac/r9600_backlight.o: pmac/r9600_backlight.c pommed.h lcd_backlight.h conffile.h dbus.h
+pmac/sysfs_backlight.o: pmac/sysfs_backlight.c pommed.h lcd_backlight.h conffile.h dbus.h
pmac/r128_backlight.o: pmac/r128_backlight.c pommed.h lcd_backlight.h conffile.h dbus.h
Modified: trunk/pommed/lcd_backlight.h
===================================================================
--- trunk/pommed/lcd_backlight.h 2007-02-10 19:10:31 UTC (rev 255)
+++ trunk/pommed/lcd_backlight.h 2007-02-21 20:43:19 UTC (rev 256)
@@ -43,14 +43,14 @@
#else
-/* r9600_backlight.c */
+/* sysfs_backlight.c */
#define R9600_BACKLIGHT_OFF 0
#define R9600_BACKLIGHT_MAX 127
void
-r9600_backlight_step(int dir);
+sysfs_backlight_step(int dir);
int
-r9600_backlight_probe(void);
+r9600_sysfs_backlight_probe(void);
void
r9600_backlight_fix_config(void);
Deleted: trunk/pommed/pmac/r9600_backlight.c
===================================================================
--- trunk/pommed/pmac/r9600_backlight.c 2007-02-10 19:10:31 UTC (rev 255)
+++ trunk/pommed/pmac/r9600_backlight.c 2007-02-21 20:43:19 UTC (rev 256)
@@ -1,210 +0,0 @@
-/*
- * pommed - Apple laptops hotkeys handler daemon
- *
- * $Id$
- *
- * Copyright (C) 2006 Julien BLACHE <jb at jblache.org>
- * Copyright (C) 2006 Yves-Alexis Perez <corsac at corsac.net>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <syslog.h>
-#include <pci/pci.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-
-#include "../pommed.h"
-#include "../conffile.h"
-#include "../lcd_backlight.h"
-#include "../dbus.h"
-
-
-struct _lcd_bck_info lcd_bck_info;
-
-
-#define SYSFS_BACKLIGHT "/sys/class/backlight/radeonbl0"
-
-static int probed = 0;
-
-
-static int
-r9600_backlight_get(void)
-{
- int fd;
- int n;
- char buffer[4];
-
- if (!probed)
- return 0;
-
- fd = open(SYSFS_BACKLIGHT "/actual_brightness", O_RDONLY);
- if (fd < 0)
- {
- logmsg(LOG_WARNING, "Could not open sysfs actual_brightness node: %s", strerror(errno));
-
- return 0;
- }
-
- n = read(fd, buffer, sizeof(buffer) -1);
- if (n < 1)
- {
- logmsg(LOG_WARNING, "Could not read sysfs actual_brightness node");
-
- close(fd);
- return 0;
- }
- close(fd);
-
- return atoi(buffer);
-}
-
-static void
-r9600_backlight_set(int value)
-{
- FILE *fp;
-
- fp = fopen(SYSFS_BACKLIGHT "/brightness", "a");
- if (fp == NULL)
- {
- logmsg(LOG_WARNING, "Could not open sysfs brightness node: %s", strerror(errno));
-
- return;
- }
-
- fprintf(fp, "%d", value);
-
- fclose(fp);
-}
-
-void
-r9600_backlight_step(int dir)
-{
- int val;
- int newval;
-
- if (!probed)
- return;
-
- val = r9600_backlight_get();
-
- if (dir == STEP_UP)
- {
- newval = val + lcd_r9600_cfg.step;
-
- if (newval > R9600_BACKLIGHT_MAX)
- newval = R9600_BACKLIGHT_MAX;
-
- logdebug("LCD stepping +%d -> %d\n", lcd_r9600_cfg.step, newval);
- }
- else if (dir == STEP_DOWN)
- {
- newval = val - lcd_r9600_cfg.step;
-
- if (newval < R9600_BACKLIGHT_OFF)
- newval = R9600_BACKLIGHT_OFF;
-
- logdebug("LCD stepping -%d -> %d\n", lcd_r9600_cfg.step, newval);
- }
- else
- return;
-
- r9600_backlight_set(newval);
-
- mbpdbus_send_lcd_backlight(newval, val);
-
- lcd_bck_info.level = newval;
-}
-
-
-#define PCI_ID_VENDOR_ATI 0x1002
-#define PCI_ID_PRODUCT_R9600 0x4e50
-#define PCI_ID_PRODUCT_R9200 0x5c63
-
-/* Look for an ATI Radeon Mobility r9600 */
-int
-r9600_backlight_probe(void)
-{
- struct pci_access *pacc;
- struct pci_dev *dev;
-
- pacc = pci_alloc();
- if (pacc == NULL)
- {
- logmsg(LOG_ERR, "Could not allocate PCI structs");
- return -1;
- }
-
- pci_init(pacc);
- pci_scan_bus(pacc);
-
- /* Iterate over all devices */
- for(dev = pacc->devices; dev; dev = dev->next)
- {
- pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES);
- /* ATI R9600 */
- if ((dev->vendor_id == PCI_ID_VENDOR_ATI)
- && ((dev->device_id == PCI_ID_PRODUCT_R9600)
- || (dev->device_id == PCI_ID_PRODUCT_R9200)))
- {
- probed = 1;
- }
- }
-
- pci_cleanup(pacc);
-
- if (!probed)
- {
- logdebug("Failed to detect ATI R9600, aborting...\n");
- return -1;
- }
-
- lcd_bck_info.max = R9600_BACKLIGHT_MAX;
-
- /*
- * Set the initial backlight level
- * The value has been sanity checked already
- */
- if (lcd_r9600_cfg.init > -1)
- {
- r9600_backlight_set(lcd_r9600_cfg.init);
- }
-
- lcd_bck_info.level = r9600_backlight_get();
-
- return 0;
-}
-
-void
-r9600_backlight_fix_config(void)
-{
- if (lcd_r9600_cfg.init < 0)
- lcd_r9600_cfg.init = -1;
-
- if (lcd_r9600_cfg.init > R9600_BACKLIGHT_MAX)
- lcd_r9600_cfg.init = R9600_BACKLIGHT_MAX;
-
- if (lcd_r9600_cfg.step < 1)
- lcd_r9600_cfg.step = 1;
-
- if (lcd_r9600_cfg.step > (R9600_BACKLIGHT_MAX / 2))
- lcd_r9600_cfg.step = R9600_BACKLIGHT_MAX / 2;
-}
-
Copied: trunk/pommed/pmac/sysfs_backlight.c (from rev 255, trunk/pommed/pmac/r9600_backlight.c)
===================================================================
--- trunk/pommed/pmac/r9600_backlight.c 2007-02-10 19:10:31 UTC (rev 255)
+++ trunk/pommed/pmac/sysfs_backlight.c 2007-02-21 20:43:19 UTC (rev 256)
@@ -0,0 +1,203 @@
+/*
+ * pommed - Apple laptops hotkeys handler daemon
+ *
+ * $Id$
+ *
+ * Copyright (C) 2006-2007 Julien BLACHE <jb at jblache.org>
+ * Copyright (C) 2006 Yves-Alexis Perez <corsac at corsac.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <syslog.h>
+#include <pci/pci.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+#include "../pommed.h"
+#include "../conffile.h"
+#include "../lcd_backlight.h"
+#include "../dbus.h"
+
+
+#define SYSFS_DRIVER_NONE 0
+#define SYSFS_DRIVER_RADEON 1
+
+
+/* sysfs backlight driver in use */
+static int bck_driver = SYSFS_DRIVER_NONE;
+
+/* sysfs actual_brightness node path */
+static char *actual_brightness[] =
+ {
+ "/dev/null",
+ "/sys/class/backlight/radeonbl0/actual_brightness"
+ };
+
+/* sysfs brightness node path */
+static char *brightness[] =
+ {
+ "/dev/null",
+ "/sys/class/backlight/radeonbl0/brightness"
+ };
+
+
+struct _lcd_bck_info lcd_bck_info;
+
+
+static int
+sysfs_backlight_get(void)
+{
+ int fd;
+ int n;
+ char buffer[4];
+
+ if (bck_driver == SYSFS_DRIVER_NONE)
+ return 0;
+
+ fd = open(actual_brightness[bck_driver], O_RDONLY);
+ if (fd < 0)
+ {
+ logmsg(LOG_WARNING, "Could not open sysfs actual_brightness node: %s", strerror(errno));
+
+ return 0;
+ }
+
+ n = read(fd, buffer, sizeof(buffer) -1);
+ if (n < 1)
+ {
+ logmsg(LOG_WARNING, "Could not read sysfs actual_brightness node");
+
+ close(fd);
+ return 0;
+ }
+ close(fd);
+
+ return atoi(buffer);
+}
+
+static void
+sysfs_backlight_set(int value)
+{
+ FILE *fp;
+
+ fp = fopen(brightness[bck_driver], "a");
+ if (fp == NULL)
+ {
+ logmsg(LOG_WARNING, "Could not open sysfs brightness node: %s", strerror(errno));
+
+ return;
+ }
+
+ fprintf(fp, "%d", value);
+
+ fclose(fp);
+}
+
+void
+sysfs_backlight_step(int dir)
+{
+ int val;
+ int newval;
+
+ if (bck_driver == SYSFS_DRIVER_NONE)
+ return;
+
+ val = sysfs_backlight_get();
+
+ if (dir == STEP_UP)
+ {
+ newval = val + lcd_r9600_cfg.step;
+
+ if (newval > R9600_BACKLIGHT_MAX)
+ newval = R9600_BACKLIGHT_MAX;
+
+ logdebug("LCD stepping +%d -> %d\n", lcd_r9600_cfg.step, newval);
+ }
+ else if (dir == STEP_DOWN)
+ {
+ newval = val - lcd_r9600_cfg.step;
+
+ if (newval < R9600_BACKLIGHT_OFF)
+ newval = R9600_BACKLIGHT_OFF;
+
+ logdebug("LCD stepping -%d -> %d\n", lcd_r9600_cfg.step, newval);
+ }
+ else
+ return;
+
+ sysfs_backlight_set(newval);
+
+ mbpdbus_send_lcd_backlight(newval, val);
+
+ lcd_bck_info.level = newval;
+}
+
+
+/* Look for the radeon backlight driver */
+int
+r9600_sysfs_backlight_probe(void)
+{
+ if (!access(brightness[SYSFS_DRIVER_RADEON], W_OK))
+ {
+ logdebug("Failed to access brightness node: %s\n", strerror(errno));
+ return -1;
+ }
+
+ if (!access(actual_brightness[SYSFS_DRIVER_RADEON], R_OK))
+ {
+ logdebug("Failed to access actual_brightness node: %s\n", strerror(errno));
+ return -1;
+ }
+
+ bck_driver = SYSFS_DRIVER_RADEON;
+
+ lcd_bck_info.max = R9600_BACKLIGHT_MAX;
+
+ /*
+ * Set the initial backlight level
+ * The value has been sanity checked already
+ */
+ if (lcd_r9600_cfg.init > -1)
+ {
+ sysfs_backlight_set(lcd_r9600_cfg.init);
+ }
+
+ lcd_bck_info.level = sysfs_backlight_get();
+
+ return 0;
+}
+
+void
+r9600_backlight_fix_config(void)
+{
+ if (lcd_r9600_cfg.init < 0)
+ lcd_r9600_cfg.init = -1;
+
+ if (lcd_r9600_cfg.init > R9600_BACKLIGHT_MAX)
+ lcd_r9600_cfg.init = R9600_BACKLIGHT_MAX;
+
+ if (lcd_r9600_cfg.step < 1)
+ lcd_r9600_cfg.step = 1;
+
+ if (lcd_r9600_cfg.step > (R9600_BACKLIGHT_MAX / 2))
+ lcd_r9600_cfg.step = R9600_BACKLIGHT_MAX / 2;
+}
+
Modified: trunk/pommed/pommed.c
===================================================================
--- trunk/pommed/pommed.c 2007-02-10 19:10:31 UTC (rev 255)
+++ trunk/pommed/pommed.c 2007-02-21 20:43:19 UTC (rev 256)
@@ -72,32 +72,32 @@
/* PowerBook5,5 */
struct machine_ops pb55_ops = {
.type = MACHINE_POWERBOOK_55,
- .lcd_backlight_probe = r9600_backlight_probe,
- .lcd_backlight_step = r9600_backlight_step,
+ .lcd_backlight_probe = r9600_sysfs_backlight_probe,
+ .lcd_backlight_step = sysfs_backlight_step,
.evdev_identify = evdev_is_adb,
};
/* PowerBook5,6 / PowerBook G4 15" (Feb 2005) */
struct machine_ops pb56_ops = {
.type = MACHINE_POWERBOOK_56,
- .lcd_backlight_probe = r9600_backlight_probe,
- .lcd_backlight_step = r9600_backlight_step,
+ .lcd_backlight_probe = r9600_sysfs_backlight_probe,
+ .lcd_backlight_step = sysfs_backlight_step,
.evdev_identify = evdev_is_fountain,
};
/* PowerBook5,7 */
struct machine_ops pb57_ops = {
.type = MACHINE_POWERBOOK_57,
- .lcd_backlight_probe = r9600_backlight_probe,
- .lcd_backlight_step = r9600_backlight_step,
+ .lcd_backlight_probe = r9600_sysfs_backlight_probe,
+ .lcd_backlight_step = sysfs_backlight_step,
.evdev_identify = evdev_is_fountain,
};
/* PowerBook6,3 */
struct machine_ops pb63_ops = {
.type = MACHINE_POWERBOOK_63,
- .lcd_backlight_probe = r9600_backlight_probe,
- .lcd_backlight_step = r9600_backlight_step,
+ .lcd_backlight_probe = r9600_sysfs_backlight_probe,
+ .lcd_backlight_step = sysfs_backlight_step,
.evdev_identify = evdev_is_adb,
};
More information about the Pommed-commits
mailing list