hal: Branch 'master'

David Zeuthen david at kemper.freedesktop.org
Mon Jan 8 09:53:31 PST 2007


 configure.in                                 |    7 
 fdi/policy/10osvendor/Makefile.am            |    4 
 hald/linux/addons/Makefile.am                |   10 
 hald/linux/addons/addon-nokia770-backlight.c |  271 +++++++++++++++++++++++++++
 4 files changed, 292 insertions(+)

New commits:
diff-tree 158636d2efebe95d9129a5e2fcb7cc09899badc9 (from 91e7fd50a7f5b427f09e91e134f12d6edf552770)
Author: Sergey Lapin <slapinid at gmail.com>
Date:   Mon Jan 8 12:53:28 2007 -0500

    add Nokia 770 backlight addon
    
    It adds addon to support n770 backlight operation.
    It is cleaned-up version. Tried to implement all
    David suggestions.

diff --git a/configure.in b/configure.in
index 68f4f2b..5eaf375 100644
--- a/configure.in
+++ b/configure.in
@@ -535,6 +535,13 @@ elif test "x$with_macbookpro" = "x" ; th
 fi
 AM_CONDITIONAL(BUILD_MACBOOKPRO, test x$BUILD_MACBOOKPRO = xyes)
 
+AC_ARG_WITH(nokia770,     [  --with-nokia770       Whether to build Nokia 770 utils (no)])
+BUILD_N770=no
+if test "x$with_nokia770" = "xyes"; then
+    BUILD_N770=yes
+fi
+AM_CONDITIONAL(BUILD_N770, test x$BUILD_N770 = xyes)
+
 dnl cpufreq
 AC_ARG_WITH(cpufreq,        [  --with-cpufreq          Whether to build cpufreq utils (auto)])
 BUILD_CPUFREQ=no
diff --git a/fdi/policy/10osvendor/Makefile.am b/fdi/policy/10osvendor/Makefile.am
index 39c8507..af2332c 100644
--- a/fdi/policy/10osvendor/Makefile.am
+++ b/fdi/policy/10osvendor/Makefile.am
@@ -21,6 +21,10 @@ if BUILD_USBCSR
 dist_fdi_DATA += 10-usbcsr-mice.fdi
 endif
 
+if BUILD_N770
+dist_fdi_DATA += 10-nokia770-backlight.fdi
+endif
+
 check:
 	for f in $(dist_fdi_DATA); do \
             echo -n "Validate XML in $$f : "; \
diff --git a/hald/linux/addons/Makefile.am b/hald/linux/addons/Makefile.am
index aa23f6e..eb5496e 100644
--- a/hald/linux/addons/Makefile.am
+++ b/hald/linux/addons/Makefile.am
@@ -25,6 +25,11 @@ libexec_PROGRAMS  += 			\
 	hald-addon-acpi-buttons-toshiba
 endif
 
+if BUILD_N770
+libexec_PROGRAMS  +=			\
+	hald-addon-nokia770-backlight
+endif
+
 if BUILD_MACBOOKPRO
 libexec_PROGRAMS += hald-addon-macbookpro-backlight
 hald_addon_macbookpro_backlight_SOURCES = addon-macbookpro-backlight.c ../../logger.c
@@ -62,3 +67,8 @@ hald_addon_pmu_LDADD = $(top_builddir)/l
 
 hald_addon_storage_SOURCES = addon-storage.c ../../logger.c ../../util_helper.c
 hald_addon_storage_LDADD = $(top_builddir)/libhal/libhal.la
+
+if BUILD_N770
+hald_addon_nokia770_backlight_SOURCES = addon-nokia770-backlight.c ../../logger.c ../../util_helper.c
+hald_addon_nokia770_backlight_LDADD = $(top_builddir)/libhal/libhal.la @GLIB_LIBS@
+endif
diff --git a/hald/linux/addons/addon-nokia770-backlight.c b/hald/linux/addons/addon-nokia770-backlight.c
new file mode 100644
index 0000000..b9cefe1
--- /dev/null
+++ b/hald/linux/addons/addon-nokia770-backlight.c
@@ -0,0 +1,271 @@
+/***************************************************************************
+ * CVSID: $Id$
+ *
+ * addon-nokia770-backlight.c : daemon, handling Nokia 770
+ * non-standard backlight. Based on macbookpro addon by
+ * David Zeuthen and Nicolas Boichat
+ *
+ * Copyright (C) 2006 Sergey Lapin <slapinid at gmail.com>
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * 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; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ **************************************************************************/
+
+#include <config.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/io.h>
+#include <sys/mman.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h> 
+
+#include <glib/gmain.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+
+#include "libhal/libhal.h"
+#include "../../logger.h"
+#include "../../util_helper.h"
+
+
+static GMainLoop *main_loop;
+static LibHalContext *halctx = NULL;
+static char * udi;
+static DBusConnection *conn;
+
+#define NUM_BUF_LEN 11
+
+static char buffer[NUM_BUF_LEN];
+
+struct backlight
+{
+    void (*set_backlight_level)(struct backlight * bl, int i);
+    int (*get_backlight_level)(struct backlight * bl);
+    void (*backlight_init)(struct backlight * bl);
+    int bl_min;
+    int bl_max;
+};
+
+struct backlight bl_data;
+
+/* Reads backligh level */
+static int read_backlight(struct backlight * bl)
+{
+ int fd;
+
+ fd = open("/sys/devices/platform/omapfb/panel/backlight_level", O_RDONLY);
+ if(fd <0 || read(fd, buffer, NUM_BUF_LEN) < 0)
+    return -1;
+
+ return atoi(buffer);
+}
+
+/* Read maximum bl level */
+/* TODO: set actual maximum level in property.
+   No we have fixed value in FDI file, but it
+   is better to set it in addon code.
+*/
+static void backlight_init(struct backlight * bl)
+{
+    int fd;
+
+    /* Reading maximum backlight level */
+    fd = open("/sys/devices/platform/omapfb/panel/backlight_max", O_RDONLY);
+
+    if(fd <0 || read(fd, buffer, NUM_BUF_LEN - 1) < 0)
+	return;
+
+    bl->bl_max = atoi(buffer);
+    close(fd);
+}
+
+/* Setting backlight level */
+static void write_backlight(struct backlight * bl, int level)
+{
+    int fd, l;
+
+    /* sanity-checking level we're required to set */
+    if(level > bl->bl_max)
+	level = bl->bl_max;
+
+    if(level < bl->bl_min)
+	level = bl->bl_min;
+
+    fd = open("/sys/devices/platform/omapfb/panel/backlight_level", O_WRONLY);
+    l = snprintf(buffer, NUM_BUF_LEN - 1, "%d", level);
+
+    if(l >= (NUM_BUF_LEN - 1)) {
+	close(fd);
+	return;
+    }
+
+    write(fd, buffer, l);
+    close(fd);
+}
+
+/* DBus filter function */
+static DBusHandlerResult
+filter_function (DBusConnection *connection, DBusMessage *message, void *userdata)
+{
+	DBusError err;
+	DBusMessage *reply;
+
+#ifdef DEBUG_N770_BL
+	dbg ("filter_function: sender=%s destination=%s obj_path=%s interface=%s method=%s", 
+	     dbus_message_get_sender (message), 
+	     dbus_message_get_destination (message), 
+	     dbus_message_get_path (message), 
+	     dbus_message_get_interface (message),
+	     dbus_message_get_member (message));
+#endif
+	reply = NULL;
+
+	if (dbus_message_is_method_call (message, 
+					 "org.freedesktop.Hal.Device.LaptopPanel", 
+					 "SetBrightness")) {
+		int brightness;
+
+		dbus_error_init (&err);
+		if (dbus_message_get_args (message, 
+					   &err,
+					   DBUS_TYPE_INT32, &brightness,
+					   DBUS_TYPE_INVALID)) {
+			if (brightness < 0 || brightness > 228) {
+				reply = dbus_message_new_error (message,
+								"org.freedesktop.Hal.Device.LaptopPanel.Invalid",
+								"Brightness has to be between 0 and 228!");
+
+			} else {
+				int return_code;
+
+				bl_data.set_backlight_level (&bl_data, brightness);
+
+				reply = dbus_message_new_method_return (message);
+				if (reply == NULL)
+					goto error;
+
+				return_code = 0;
+				dbus_message_append_args (reply,
+							  DBUS_TYPE_INT32, &return_code,
+							  DBUS_TYPE_INVALID);
+			}
+
+			dbus_connection_send (connection, reply, NULL);
+		}
+		
+	} else if (dbus_message_is_method_call (message, 
+						"org.freedesktop.Hal.Device.LaptopPanel", 
+						"GetBrightness")) {
+		int brightness;
+
+		dbus_error_init (&err);
+		if (dbus_message_get_args (message, 
+					   &err,
+					   DBUS_TYPE_INVALID)) {
+
+			brightness = bl_data.get_backlight_level (&bl_data);
+			if (brightness < bl_data.bl_min)
+				brightness = bl_data.bl_min;
+			if (brightness > bl_data.bl_max)
+				brightness = bl_data.bl_max;
+
+			/* dbg ("getting brightness, it's %d", brightness); */
+
+			reply = dbus_message_new_method_return (message);
+			if (reply == NULL)
+				goto error;
+
+			dbus_message_append_args (reply,
+						  DBUS_TYPE_INT32, &brightness,
+						  DBUS_TYPE_INVALID);
+			dbus_connection_send (connection, reply, NULL);
+		}
+		
+	}
+	
+error:
+	if (reply != NULL)
+		dbus_message_unref (reply);
+
+	return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+/* Setting-up backlight structure */
+static void setup_cb(void)
+{
+ memset(&bl_data, 0, sizeof(struct backlight));
+ bl_data.backlight_init = backlight_init;
+ bl_data.get_backlight_level = read_backlight;
+ bl_data.set_backlight_level = write_backlight;
+}
+
+int
+main (int argc, char *argv[])
+{
+	DBusError err;
+
+	setup_logger ();
+	setup_cb();
+	udi = getenv ("UDI");
+
+	HAL_DEBUG (("udi=%s", udi));
+	if (udi == NULL) {
+		HAL_ERROR (("No device specified"));
+		return -2;
+	}
+
+	dbus_error_init (&err);
+	if ((halctx = libhal_ctx_init_direct (&err)) == NULL) {
+		HAL_ERROR (("Cannot connect to hald"));
+		return -3;
+	}
+
+
+
+	conn = libhal_ctx_get_dbus_connection (halctx);
+	dbus_connection_setup_with_g_main (conn, NULL);
+
+	dbus_connection_add_filter (conn, filter_function, NULL, NULL);
+
+	if (!libhal_device_claim_interface (halctx, 
+					    "/org/freedesktop/Hal/devices/omapfb_bl", 
+					    "org.freedesktop.Hal.Device.LaptopPanel", 
+					    "    <method name=\"SetBrightness\">\n"
+					    "      <arg name=\"brightness_value\" direction=\"in\" type=\"i\"/>\n"
+					    "      <arg name=\"return_code\" direction=\"out\" type=\"i\"/>\n"
+					    "    </method>\n"
+					    "    <method name=\"GetBrightness\">\n"
+					    "      <arg name=\"brightness_value\" direction=\"out\" type=\"i\"/>\n"
+					    "    </method>\n",
+					    &err)) {
+		HAL_ERROR (("Cannot claim interface 'org.freedesktop.Hal.Device.LaptopPanel'"));
+		return -4;
+	}
+	dbus_error_init (&err);
+	if (!libhal_device_addon_is_ready (halctx, udi, &err)) {
+		return -4;
+	}
+	bl_data.backlight_init(&bl_data);
+	main_loop = g_main_loop_new (NULL, FALSE);
+	g_main_loop_run (main_loop);
+	return 0;
+}


More information about the hal-commit mailing list