Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * pommed - Apple laptops hotkeys handler daemon
- *
- * MacBook Backlight Control (Intel GMA950 & GMA965)
- *
- * Copyright (C) 2006-2007 Ryan Lortie <desrt@desrt.ca>
- * Copyright (C) 2006-2007 Julien BLACHE <jb@jblache.org>
- * + Adapted for pommed
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * 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.
- *
- *
- * The GMA950 has a backlight control register at offset 0x00061254 in its
- * PCI memory space (512K region):
- * - bits 0-15 represent the backlight value
- * - bits 16 indicates legacy mode is in use when set
- * - bits 17-31 hold the max backlight value << 1
- *
- * Bit 16 indicates whether the backlight control should be used in legacy
- * mode or not. This bit is 0 on MacBooks, indicating native mode should be
- * used. This is the only method supported here.
- *
- *
- * The GMA965 is slightly different; the backlight control register is at
- * offset 0x00061250 in its PCI memory space (first 512K in the 1M region):
- * - bits 0-15 represent the backlight value
- * - bits 16-31 hold the max backlight value
- * - bit 30 indicates legacy mode is in use when set
- *
- *
- * For BOTH cards, the register for the backlight value is at offset 0x00061254.
- *
- *
- * For both cards, in the code below, max value and current value are expressed
- * on 15 bits; the values are shifted as appropriate when appropriate.
- */
- #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"
- static unsigned int GMA950_BACKLIGHT_MAX;
- static int fd = -1;
- static char *memory = NULL;
- static char sysfs_resource[64];
- static long length = 0;
- #define REGISTER_OFFSET 0x00061254
- #define GMA950_LEGACY_MODE (1 << 16)
- #define GMA950_CONTROL_REGISTER 0x00061254
- #define GMA965_LEGACY_MODE (1 << 30)
- #define GMA965_CONTROL_REGISTER 0x00061250
- static inline unsigned int
- readl(const volatile void *addr)
- {
- return *(volatile unsigned int*) addr;
- }
- static inline void
- writel(unsigned int b, volatile void *addr)
- {
- *(volatile unsigned int*) addr = b;
- }
- #define INREG(addr) readl(memory+addr)
- #define OUTREG(addr,val) writel(val, memory+addr)
- static unsigned int
- gma950_backlight_get(void)
- {
- return (INREG(REGISTER_OFFSET) >> 1) & 0x7fff;
- }
- static unsigned int
- gma950_backlight_get_max(void)
- {
- return (INREG(REGISTER_OFFSET) >> 17);
- }
- static void
- gma950_backlight_set(unsigned int value)
- {
- OUTREG(REGISTER_OFFSET, (GMA950_BACKLIGHT_MAX << 17) | (value << 1));
- }
- static int
- gma950_backlight_map(void)
- {
- return 0;
- }
- static void
- gma950_backlight_unmap(void)
- {
- }
- void
- gma950_backlight_step(int dir)
- {
- }
- void
- gma950_backlight_toggle(int lvl)
- {
- }
- /*
- * We are hardware-dependent for GMA950_BACKLIGHT_MAX,
- * so here _fix_config() is static and called at probe time.
- */
- static void
- gma950_backlight_fix_config(void)
- {
- }
- #define PCI_ID_VENDOR_INTEL 0x8086
- #define PCI_ID_PRODUCT_GMA950 0x27A2
- #define PCI_ID_PRODUCT_GMA965 0x2A02
- /* Look for an Intel GMA950 or GMA965 */
- int
- gma950_backlight_probe(void)
- {
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement