[Pommed-commits] r345 - in trunk: . pommed pommed/mactel

jblache at alioth.debian.org jblache at alioth.debian.org
Fri Jul 27 14:00:46 UTC 2007


Author: jblache
Date: 2007-07-27 14:00:46 +0000 (Fri, 27 Jul 2007)
New Revision: 345

Added:
   trunk/pommed/mactel/nv8600mgt_backlight.c
Modified:
   trunk/ChangeLog
   trunk/pommed.conf.mactel
   trunk/pommed/Makefile
   trunk/pommed/conffile.c
   trunk/pommed/conffile.h
   trunk/pommed/lcd_backlight.h
   trunk/pommed/pommed.c
Log:
Add support for the nVidia GeForce 8600M GT found in the MacBookPro3,1.


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2007-07-27 13:52:53 UTC (rev 344)
+++ trunk/ChangeLog	2007-07-27 14:00:46 UTC (rev 345)
@@ -12,6 +12,9 @@
 	- gpomme: adjust for the new LCD backlight notification.
 	- Add the gpomme icon contributed by Jan Larres
 	<jan at majutsushi.net> under the icons/ directory.
+	- pommed: add support for the nVidia GeForce 8600M GT found in the
+	MacBookPro3,1. I don't like that code, if there's something better
+	that can be used, please mail me.
 
 version 1.7:
 	- pommed: add partial support for the MacBookPro3,1 (Core2 Duo,

Modified: trunk/pommed/Makefile
===================================================================
--- trunk/pommed/Makefile	2007-07-27 13:52:53 UTC (rev 344)
+++ trunk/pommed/Makefile	2007-07-27 14:00:46 UTC (rev 345)
@@ -40,6 +40,7 @@
 
 SOURCES = pommed.c cd_eject.c evdev.c conffile.c audio.c dbus.c power.c \
 		mactel/x1600_backlight.c mactel/gma950_backlight.c \
+		mactel/nv8600mgt_backlight.c \
 		mactel/kbd_backlight.c mactel/ambient.c mactel/acpi.c
 
 LIBS = /usr/lib/libpci.a
@@ -90,6 +91,8 @@
 
 mactel/gma950_backlight.o: mactel/gma950_backlight.c pommed.h lcd_backlight.h conffile.h dbus.h
 
+mactel/nv8600mgt_backlight.o: mactel/nv8600mgt_backlight.c pommed.h lcd_backlight.h conffile.h dbus.h
+
 mactel/kbd_backlight.o: mactel/kbd_backlight.c kbd_auto.c kbd_backlight.h pommed.h ambient.h conffile.h dbus.h
 
 mactel/ambient.o: mactel/ambient.c ambient.h pommed.h dbus.h

Modified: trunk/pommed/conffile.c
===================================================================
--- trunk/pommed/conffile.c	2007-07-27 13:52:53 UTC (rev 344)
+++ trunk/pommed/conffile.c	2007-07-27 14:00:46 UTC (rev 345)
@@ -41,6 +41,7 @@
 #else
 struct _lcd_x1600_cfg lcd_x1600_cfg;
 struct _lcd_gma950_cfg lcd_gma950_cfg;
+struct _lcd_nv8600mgt_cfg lcd_nv8600mgt_cfg;
 #endif
 struct _audio_cfg audio_cfg;
 struct _kbd_cfg kbd_cfg;
@@ -93,6 +94,14 @@
     CFG_END()
   };
 
+static cfg_opt_t lcd_nv8600mgt_opts[] =
+  {
+    CFG_INT("init", -1, CFGF_NONE),
+    CFG_INT("step", 1, CFGF_NONE),
+    CFG_INT("on_batt", 0, CFGF_NONE),
+    CFG_END()
+  };
+
 static cfg_opt_t audio_opts[] =
   {
     CFG_STR("card", "default", CFGF_NONE),
@@ -139,6 +148,7 @@
 #else
     CFG_SEC("lcd_x1600", lcd_x1600_opts, CFGF_NONE),
     CFG_SEC("lcd_gma950", lcd_gma950_opts, CFGF_NONE),
+    CFG_SEC("lcd_nv8600mgt", lcd_nv8600mgt_opts, CFGF_NONE),
 #endif
     CFG_SEC("audio", audio_opts, CFGF_NONE),
     CFG_SEC("kbd", kbd_opts, CFGF_NONE),
@@ -199,6 +209,10 @@
   printf("    initial level: 0x%x\n", lcd_gma950_cfg.init);
   printf("    step: 0x%x\n", lcd_gma950_cfg.step);
   printf("    on_batt: 0x%x\n", lcd_gma950_cfg.on_batt);
+  printf(" + nVidia GeForce 8600M GT backlight control:\n");
+  printf("    initial level: %d\n", lcd_nv8600mgt_cfg.init);
+  printf("    step: %d\n", lcd_nv8600mgt_cfg.step);
+  printf("    on_batt: %d\n", lcd_nv8600mgt_cfg.on_batt);
 #endif /* __powerpc__ */
   printf(" + Audio volume control:\n");
   printf("    card: %s\n", audio_cfg.card);
@@ -254,6 +268,9 @@
   /* lcd_gma950 */
   cfg_set_validate_func(cfg, "lcd_gma950|step", config_validate_positive_integer);
   cfg_set_validate_func(cfg, "lcd_gma950|on_batt", config_validate_positive_integer);
+  /* lcd_nv8600mgt */
+  cfg_set_validate_func(cfg, "lcd_nv8600mgt|step", config_validate_positive_integer);
+  cfg_set_validate_func(cfg, "lcd_nv8600mgt|on_batt", config_validate_positive_integer);
 #endif /* __powerpc__ */
   /* audio */
   cfg_set_validate_func(cfg, "audio|card", config_validate_string);
@@ -314,6 +331,12 @@
   lcd_gma950_cfg.on_batt = cfg_getint(sec, "on_batt");
   /* No _fix_config() call here, as we're hardware-dependent
    * for the max backlight value */
+
+  sec = cfg_getsec(cfg, "lcd_nv8600mgt");
+  lcd_nv8600mgt_cfg.init = cfg_getint(sec, "init");
+  lcd_nv8600mgt_cfg.step = cfg_getint(sec, "step");
+  lcd_nv8600mgt_cfg.on_batt = cfg_getint(sec, "on_batt");
+  nv8600mgt_backlight_fix_config();
 #endif /* __powerpc__ */
 
   sec = cfg_getsec(cfg, "audio");

Modified: trunk/pommed/conffile.h
===================================================================
--- trunk/pommed/conffile.h	2007-07-27 13:52:53 UTC (rev 344)
+++ trunk/pommed/conffile.h	2007-07-27 14:00:46 UTC (rev 345)
@@ -29,6 +29,13 @@
   unsigned int step;
   unsigned int on_batt;
 };
+
+struct _lcd_nv8600mgt_cfg {
+  int init;
+  int step;
+  int on_batt;
+};
+
 #endif /* __powerpc__ */
 
 struct _audio_cfg {
@@ -66,6 +73,7 @@
 #else
 extern struct _lcd_x1600_cfg lcd_x1600_cfg;
 extern struct _lcd_gma950_cfg lcd_gma950_cfg;
+extern struct _lcd_nv8600mgt_cfg lcd_nv8600mgt_cfg;
 #endif
 extern struct _audio_cfg audio_cfg;
 extern struct _kbd_cfg kbd_cfg;

Modified: trunk/pommed/lcd_backlight.h
===================================================================
--- trunk/pommed/lcd_backlight.h	2007-07-27 13:52:53 UTC (rev 344)
+++ trunk/pommed/lcd_backlight.h	2007-07-27 14:00:46 UTC (rev 345)
@@ -55,6 +55,24 @@
 gma950_backlight_probe(void);
 
 
+/* nv8600mgt_backlight.c */
+#define NV8600MGT_BACKLIGHT_OFF    0
+#define NV8600MGT_BACKLIGHT_MAX    15
+
+void
+nv8600mgt_backlight_step(int dir);
+
+void
+nv8600mgt_backlight_toggle(int lvl);
+
+int
+nv8600mgt_backlight_probe(void);
+
+void
+nv8600mgt_backlight_fix_config(void);
+
+
+
 #else
 
 

Added: trunk/pommed/mactel/nv8600mgt_backlight.c
===================================================================
--- trunk/pommed/mactel/nv8600mgt_backlight.c	                        (rev 0)
+++ trunk/pommed/mactel/nv8600mgt_backlight.c	2007-07-27 14:00:46 UTC (rev 345)
@@ -0,0 +1,251 @@
+/*
+ * pommed - Apple laptops hotkeys handler daemon
+ *
+ * Apple Macbook Pro LCD backlight control, nVidia 8600M GT
+ *
+ * $Id$
+ *
+ * Copyright (C) 2006 Nicolas Boichat <nicolas @boichat.ch>
+ * Copyright (C) 2006 Felipe Alfaro Solana <felipe_alfaro @linuxmail.org>
+ * Copyright (C) 2007 Julien BLACHE <jb at jblache.org>
+ *  + Adapted for pommed
+ *
+ * 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 Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include <stdio.h>
+#include <sys/io.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <syslog.h>
+
+#include <errno.h>
+
+#include <pci/pci.h>
+
+#include "../pommed.h"
+#include "../conffile.h"
+#include "../lcd_backlight.h"
+#include "../dbus.h"
+
+
+struct _lcd_bck_info lcd_bck_info;
+
+
+static int nv8600mgt_inited = 0;
+
+
+static unsigned char
+nv8600mgt_backlight_get()
+{
+  unsigned char value;
+
+  if (nv8600mgt_inited == 0)
+    return 0;
+
+  outb(0x03, 0xB3);
+  outb(0xBF, 0xB2);
+
+  value = inb(0xB3) >> 4;
+
+  return value;
+}
+
+static void
+nv8600mgt_backlight_set(unsigned char value)
+{
+  if (nv8600mgt_inited == 0)
+    return;
+
+  outb(0x04 | (value << 4), 0xB3);
+  outb(0xBF, 0xB2);
+}
+
+
+void
+nv8600mgt_backlight_step(int dir)
+{
+  int val;
+  int newval;
+
+  if (nv8600mgt_inited == 0)
+    return;
+
+  val = nv8600mgt_backlight_get();
+
+  if (dir == STEP_UP)
+    {
+      newval = val + lcd_nv8600mgt_cfg.step;
+
+      if (newval > NV8600MGT_BACKLIGHT_MAX)
+	newval = NV8600MGT_BACKLIGHT_MAX;
+
+      logdebug("LCD stepping +%d -> %d\n", lcd_nv8600mgt_cfg.step, newval);
+    }
+  else if (dir == STEP_DOWN)
+    {
+      newval = val - lcd_nv8600mgt_cfg.step;
+
+      if (newval < NV8600MGT_BACKLIGHT_OFF)
+	newval = NV8600MGT_BACKLIGHT_OFF;
+
+      logdebug("LCD stepping -%d -> %d\n", lcd_nv8600mgt_cfg.step, newval);
+    }
+  else
+    return;
+
+  nv8600mgt_backlight_set((unsigned char)newval);
+
+  mbpdbus_send_lcd_backlight(newval, val, LCD_USER);
+
+  lcd_bck_info.level = newval;
+}
+
+void
+nv8600mgt_backlight_toggle(int lvl)
+{
+  if (lcd_nv8600mgt_cfg.on_batt == 0)
+    return;
+
+  if (nv8600mgt_inited == 0)
+    return;
+
+  switch (lvl)
+    {
+      case LCD_ON_AC_LEVEL:
+	logdebug("LCD switching to AC level\n");
+
+	nv8600mgt_backlight_set(lcd_bck_info.ac_lvl);
+
+	mbpdbus_send_lcd_backlight(lcd_bck_info.ac_lvl, lcd_bck_info.level, LCD_AUTO);
+
+	lcd_bck_info.level = lcd_bck_info.ac_lvl;
+	break;
+
+      case LCD_ON_BATT_LEVEL:
+	logdebug("LCD switching to battery level\n");
+
+	lcd_bck_info.ac_lvl = lcd_bck_info.level;
+
+	if (lcd_bck_info.level > lcd_nv8600mgt_cfg.on_batt)
+	  {
+	    nv8600mgt_backlight_set(lcd_nv8600mgt_cfg.on_batt);
+	    lcd_bck_info.level = lcd_nv8600mgt_cfg.on_batt;
+
+	    mbpdbus_send_lcd_backlight(lcd_bck_info.level, lcd_bck_info.ac_lvl, LCD_AUTO);
+	  }
+	break;
+    }
+}
+
+
+#define PCI_ID_VENDOR_NVIDIA     0x10de
+#define PCI_ID_PRODUCT_8600MGT   0x0407
+
+/* Look for an nVidia GeForce 8600M GT */
+int
+nv8600mgt_backlight_probe(void)
+{
+  struct pci_access *pacc;
+  struct pci_dev *dev;
+  int nv_found = 0;
+
+  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);
+      /* nVidia GeForce 8600M GT */
+      if ((dev->vendor_id == PCI_ID_VENDOR_NVIDIA)
+	  && (dev->device_id == PCI_ID_PRODUCT_8600MGT))
+	{
+	  nv_found = 1;
+
+	  break;
+	}
+    }
+
+  pci_cleanup(pacc);
+
+  if (!nv_found)
+    {
+      logdebug("Failed to detect nVidia GeForce 8600M GT, aborting...\n");
+      return -1;
+    }
+
+  lcd_bck_info.max = NV8600MGT_BACKLIGHT_MAX;
+
+  if (ioperm(0xB2, 0xB3, 1) < 0)
+    {
+      logmsg(LOG_ERR, "ioperm() failed: %s", strerror(errno));
+
+      lcd_bck_info.level = 0;
+
+      return -1;
+    }
+
+  nv8600mgt_inited = 1;
+
+  /*
+   * Set the initial backlight level
+   * The value has been sanity checked already
+   */
+  if (lcd_nv8600mgt_cfg.init > -1)
+    {
+      nv8600mgt_backlight_set((unsigned char)lcd_nv8600mgt_cfg.init);
+    }
+
+  lcd_bck_info.level = nv8600mgt_backlight_get();
+  lcd_bck_info.ac_lvl = lcd_bck_info.level;
+
+  return 0;
+}
+
+
+void
+nv8600mgt_backlight_fix_config(void)
+{
+  if (lcd_nv8600mgt_cfg.init < 0)
+    lcd_nv8600mgt_cfg.init = -1;
+
+  if (lcd_nv8600mgt_cfg.init > NV8600MGT_BACKLIGHT_MAX)
+    lcd_nv8600mgt_cfg.init = NV8600MGT_BACKLIGHT_MAX;
+
+  if (lcd_nv8600mgt_cfg.step < 1)
+    lcd_nv8600mgt_cfg.step = 1;
+
+  if (lcd_nv8600mgt_cfg.step > (NV8600MGT_BACKLIGHT_MAX / 4))
+    lcd_nv8600mgt_cfg.step = NV8600MGT_BACKLIGHT_MAX / 4;
+
+  if ((lcd_nv8600mgt_cfg.on_batt > NV8600MGT_BACKLIGHT_MAX)
+      || (lcd_nv8600mgt_cfg.on_batt < NV8600MGT_BACKLIGHT_OFF))
+    lcd_nv8600mgt_cfg.on_batt = 0;
+}


Property changes on: trunk/pommed/mactel/nv8600mgt_backlight.c
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: trunk/pommed/pommed.c
===================================================================
--- trunk/pommed/pommed.c	2007-07-27 13:52:53 UTC (rev 344)
+++ trunk/pommed/pommed.c	2007-07-27 14:00:46 UTC (rev 345)
@@ -240,21 +240,6 @@
 
 #else
 
-int dummy_backlight_probe(void)
-{
-  return 0;
-}
-
-void dummy_backlight_step(int dir)
-{
-  return;
-}
-
-void dummy_backlight_toggle(int lvl)
-{
-  return;
-}
-
 struct machine_ops mb_mops[] = {
   /* MacBook Pro machines */
 
@@ -276,10 +261,9 @@
 
   {  /* MacBookPro3,1 (15" & 17", Core2 Duo, June 2007) */
     .type = MACHINE_MACBOOKPRO_3,
-    /* dummy backlight operations for now - nVidia support needed */
-    .lcd_backlight_probe = dummy_backlight_probe,
-    .lcd_backlight_step = dummy_backlight_step,
-    .lcd_backlight_toggle = dummy_backlight_toggle,
+    .lcd_backlight_probe = nv8600mgt_backlight_probe,
+    .lcd_backlight_step = nv8600mgt_backlight_step,
+    .lcd_backlight_toggle = nv8600mgt_backlight_toggle,
     .evdev_identify = evdev_is_geyser4,
   },
 

Modified: trunk/pommed.conf.mactel
===================================================================
--- trunk/pommed.conf.mactel	2007-07-27 13:52:53 UTC (rev 344)
+++ trunk/pommed.conf.mactel	2007-07-27 14:00:46 UTC (rev 345)
@@ -9,7 +9,7 @@
 	fnmode = 1
 }
 
-# ATI X1600 backlight control (MacBook Pro)
+# ATI X1600 backlight control (MacBook Pro v1 & v2)
 lcd_x1600 {
 	# initial backlight level [200] (0 - 255, -1 to disable)
 	init = -1
@@ -29,6 +29,16 @@
 	on_batt = 0x40
 }
 
+# nVidia GeForce 8600M GT backlight control (MacBook Pro v3)
+lcd_nv8600mgt {
+	# initial backlight level [12] (0 - 15, -1 to disable)
+	init = -1
+	# step value (1 - 2)
+	step = 1
+	# backlight level when on battery [6] (1 - 15, 0 to disable)
+	on_batt = 6
+}
+
 # Audio support
 audio {
 	# Use amixer or alsamixer/alsamixergui to determine the sound card




More information about the Pommed-commits mailing list