diff -Nur hal.orig/configure.in hal/configure.in --- hal.orig/configure.in 2007-01-03 09:19:29.000000000 +0100 +++ hal/configure.in 2007-01-03 09:13:40.000000000 +0100 @@ -245,6 +245,9 @@ AM_CONDITIONAL(HAVE_LIBUSB,false) fi +dnl Check for libsmbios +AC_CHECK_LIB(smbios, SMBIOSFreeMemory, [AM_CONDITIONAL(HAVE_SMBIOS, true)], [AM_CONDITIONAL(HAVE_SMBIOS, false)]) + dnl Check for libpci AC_CHECK_HEADERS(pci/pci.h, [ AC_CHECK_LIB(pci, pci_init, [ @@ -569,6 +572,29 @@ fi AM_CONDITIONAL(BUILD_USBCSR, test x$BUILD_USBCSR = xyes) +dnl Dell backlight +AC_ARG_WITH(dell-backlight, [ --with-dell-backlight Whether to build Dell backlight support (auto)]) +BUILD_DELL=no +if test "x$with_dell_backlight" = "xyes" ; then + BUILD_DELL=yes +elif test "x$with_dell_backlight" = "x" ; then + if test "$HAVE_SMBIOS" != "false" ; then + case "${HALD_BACKEND}" in + linux) + case "${host}" in + i[[3456]]86-*-*) + BUILD_DELL=yes + ;; + *) + ;; + esac + ;; + *) + ;; + esac + fi +fi +AM_CONDITIONAL(BUILD_DELL, test x$BUILD_DELL = xyes) dnl dnl SUBSETTING END @@ -663,6 +689,7 @@ Macbook Pro utils: ${BUILD_MACBOOKPRO} (Linux only, x86 only, requires libpci) CPU frequency scaling: ${BUILD_CPUFREQ} (Linux only) USB wireless mouse power: ${BUILD_USBCSR} (Linux only, requires libusb) + Dell Backlight ${BUILD_DELL} (Linux only, requires libsmbios) Maintainer mode: ${USE_MAINTAINER_MODE} Building verbose mode: ${enable_verbose_mode} diff -Nur hal.orig/fdi/policy/10osvendor/10-dell-laptop-brightness.fdi hal/fdi/policy/10osvendor/10-dell-laptop-brightness.fdi --- hal.orig/fdi/policy/10osvendor/10-dell-laptop-brightness.fdi 1970-01-01 01:00:00.000000000 +0100 +++ hal/fdi/policy/10osvendor/10-dell-laptop-brightness.fdi 2007-01-03 09:14:19.000000000 +0100 @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + laptop_panel + laptop_panel + Dell Laptop Panel + custom + 8 + false + hald-addon-dell-backlight + + + + \ No newline at end of file diff -Nur hal.orig/fdi/policy/10osvendor/Makefile.am hal/fdi/policy/10osvendor/Makefile.am --- hal.orig/fdi/policy/10osvendor/Makefile.am 2007-01-03 09:19:29.000000000 +0100 +++ hal/fdi/policy/10osvendor/Makefile.am 2007-01-03 09:14:46.000000000 +0100 @@ -21,6 +21,10 @@ dist_fdi_DATA += 10-usbcsr-mice.fdi endif +if BUILD_DELL +dist_fdi_DATA += 10-dell-laptop-brightness.fdi +endif + check: for f in $(dist_fdi_DATA); do \ echo -n "Validate XML in $$f : "; \ Binary files hal.orig/.git/index and hal/.git/index differ diff -Nur hal.orig/hald/linux/addons/addon-dell-backlight.cpp hal/hald/linux/addons/addon-dell-backlight.cpp --- hal.orig/hald/linux/addons/addon-dell-backlight.cpp 1970-01-01 01:00:00.000000000 +0100 +++ hal/hald/linux/addons/addon-dell-backlight.cpp 2007-01-03 09:26:20.000000000 +0100 @@ -0,0 +1,252 @@ +/*************************************************************************** + * + * + * addon-dell-backlight.cpp : Sets the backlight for Dell laptops using the libsmbios interface + * + * Copyright (C) 2007 Erik Andrén + * Heavily based on the macbook addon and the dellLcdBrightness code in libsmbios. + * This program needs the dcdbas module to be loaded and libsmbios >= 0.12.1 installed + * + * 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 +#include +#include + +#include "libhal/libhal.h" +#include "../../logger.h" + +#include "smbios/ISmi.h" +#include "smbios/IToken.h" + +static LibHalContext *halctx = NULL; +static GMainLoop *main_loop; +static char *udi; +static DBusConnection *conn; +static const int DELL_LCD_BRIGHTNESS_TOKEN = 0x007d; + +using namespace std; +using namespace smi; + +typedef u32 (*readfn)(u32 location, u32 *minValue, u32 *maxValue); +typedef u32 (*writefn)(const std::string &password, u32 location, u32 value, u32 *minValue, u32 *maxValue); + +static u32 +read_backlight(dbus_bool_t ACon) +{ + u8 location = 0; + u32 minValue = 0; + u32 maxValue = 0; + u32 curValue; + readfn readFunction; + + if (ACon) + readFunction = &smi::readACModeSetting; + else + readFunction = &smi::readBatteryModeSetting; + + smbios::TokenTableFactory *ttFactory = smbios::TokenTableFactory::getFactory() ; + smbios::ITokenTable *tokenTable = ttFactory->getSingleton(); + smbios::IToken *token = &(*((*tokenTable)[ DELL_LCD_BRIGHTNESS_TOKEN ])); + dynamic_cast< smbios::ISmiToken * >(token)->getSmiDetails( static_cast(0), static_cast(0), &location ); + + try + { + curValue = readFunction(location, &minValue, &maxValue); + } + catch( const exception &e ) + { + HAL_ERROR(("Could not access the dcdbas kernel module. Please make sure it is loaded")); + return 7; + } + + if(ACon) + HAL_DEBUG(("Reading %d from the AC backlight register", curValue)); + else + HAL_DEBUG(("Reading %d from the BAT backlight register", curValue)); + + return curValue; +} + +static void +write_backlight (u32 newBacklightValue, dbus_bool_t ACon) +{ + u8 location = 0; + u32 minValue = 0; + u32 maxValue = 0; + u32 curValue; + writefn writeFunction; + string password(""); //FIXME: Implement password support + + if (ACon) + writeFunction = &smi::writeACModeSetting; + else + writeFunction = &smi::writeBatteryModeSetting; + + smbios::TokenTableFactory *ttFactory = smbios::TokenTableFactory::getFactory(); + smbios::ITokenTable *tokenTable = ttFactory->getSingleton(); + smbios::IToken *token = &(*((*tokenTable)[ DELL_LCD_BRIGHTNESS_TOKEN ])); + dynamic_cast< smbios::ISmiToken * >(token)->getSmiDetails( static_cast(0), static_cast(0), &location ); + + try + { + curValue = writeFunction(password, location, newBacklightValue, &minValue, &maxValue); + } + catch( const exception &e ) + { + HAL_ERROR(("Could not access the dcdbas kernel module. Please make sure it is loaded")); + return; + } + if(ACon) + HAL_DEBUG(("Wrote %d to the AC backlight", curValue)); + else + HAL_DEBUG(("Wrote %d to the BAT backlight", curValue)); +} + +static DBusHandlerResult +filter_function (DBusConnection *connection, DBusMessage *message, void *userdata) +{ + DBusError err; + DBusMessage *reply = NULL; + dbus_bool_t AC; + dbus_error_init (&err); + + /* Mechanism to ensure that we always set the AC brightness when we are on AC-power etc. */ + AC = libhal_device_get_property_bool (halctx, + "/org/freedesktop/Hal/devices/acpi_AC", + "ac_adapter.present", + &err); + + if (dbus_message_is_method_call (message, + "org.freedesktop.Hal.Device.LaptopPanel", + "SetBrightness")) { + int brightness; + + HAL_DEBUG(("Received SetBrightness DBus call")); + + if (dbus_message_get_args (message, + &err, + DBUS_TYPE_INT32, &brightness, + DBUS_TYPE_INVALID)) { + if (brightness < 0 || brightness > 7) { + reply = dbus_message_new_error (message, + "org.freedesktop.Hal.Device.LaptopPanel.Invalid", + "Brightness has to be between 0 and 7!"); + + } else { + int return_code; + + write_backlight (brightness, AC); + + 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")) { + HAL_DEBUG(("Received GetBrightness DBUS call")); + + if (dbus_message_get_args (message, + &err, + DBUS_TYPE_INVALID)) { + int brightness = read_backlight(AC); + if (brightness < 0) + brightness = 0; + else if (brightness > 7) + brightness = 7; + + 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; +} + +int +main (int argc, char *argv[]) +{ + DBusError err; + + setup_logger (); + + 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; + } + + dbus_error_init (&err); + if (!libhal_device_addon_is_ready (halctx, udi, &err)) { + return -4; + } + + conn = libhal_ctx_get_dbus_connection (halctx); + dbus_connection_setup_with_g_main (conn, NULL); + + dbus_connection_add_filter (conn, filter_function, NULL, NULL); + + /* this works because we hardcoded the udi's in the in the fdi files */ + if (!libhal_device_claim_interface (halctx, + "/org/freedesktop/Hal/devices/dell_lcd_panel", + "org.freedesktop.Hal.Device.LaptopPanel", + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n", + &err)) { + HAL_ERROR (("Cannot claim interface 'org.freedesktop.Hal.Device.LaptopPanel'")); + return -4; + } + + main_loop = g_main_loop_new (NULL, FALSE); + g_main_loop_run (main_loop); + return 0; +} + + diff -Nur hal.orig/hald/linux/addons/Makefile.am hal/hald/linux/addons/Makefile.am --- hal.orig/hald/linux/addons/Makefile.am 2007-01-03 09:19:29.000000000 +0100 +++ hal/hald/linux/addons/Makefile.am 2007-01-03 09:10:45.000000000 +0100 @@ -43,6 +43,12 @@ hald_addon_usb_csr_SOURCES = addon-usb-csr.c ../../logger.c ../../util_helper.c hald_addon_usb_csr_LDADD = $(top_builddir)/libhal/libhal.la -lusb @GLIB_LIBS@ endif + +if BUILD_DELL +libexec_PROGRAMS += hald-addon-dell-backlight +hald_addon_dell_backlight_SOURCES = addon-dell-backlight.cpp ../../logger.c +hald_addon_dell_backlight_LDADD = $(top_builddir)/libhal/libhal.la -lsmbios @GLIB_LIBS@ +endif endif hald_addon_acpi_SOURCES = addon-acpi.c ../../logger.c ../../util_helper.c diff -Nur hal.orig/hald/logger.h hal/hald/logger.h --- hal.orig/hald/logger.h 2007-01-03 09:19:29.000000000 +0100 +++ hal/hald/logger.h 2007-01-03 09:11:45.000000000 +0100 @@ -23,6 +23,10 @@ * **************************************************************************/ +#ifdef __cplusplus +extern "C" { +#endif + #ifndef LOGGER_H #define LOGGER_H @@ -85,3 +89,8 @@ /** @} */ #endif /* LOGGER_H */ + +#ifdef __cplusplus +} +#endif +