Advertisement
Guest User

Untitled

a guest
Jun 8th, 2013
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.94 KB | None | 0 0
  1. /*
  2.  * pommed - Apple laptops hotkeys handler daemon
  3.  *
  4.  * MacBook Backlight Control (Intel GMA950 & GMA965)
  5.  *
  6.  * Copyright (C) 2006-2007 Ryan Lortie <desrt@desrt.ca>
  7.  * Copyright (C) 2006-2007 Julien BLACHE <jb@jblache.org>
  8.  *  + Adapted for pommed
  9.  *
  10.  * This program is free software; you can redistribute it and/or modify
  11.  * it under the terms of version 2 of the GNU General Public License as
  12.  * published by the Free Software Foundation.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License along
  20.  * with this program; if not, write to the Free Software Foundation, Inc.,
  21.  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  22.  *
  23.  *
  24.  * The GMA950 has a backlight control register at offset 0x00061254 in its
  25.  * PCI memory space (512K region):
  26.  *  - bits 0-15 represent the backlight value
  27.  *  - bits 16 indicates legacy mode is in use when set
  28.  *  - bits 17-31 hold the max backlight value << 1
  29.  *
  30.  * Bit 16 indicates whether the backlight control should be used in legacy
  31.  * mode or not. This bit is 0 on MacBooks, indicating native mode should be
  32.  * used. This is the only method supported here.
  33.  *
  34.  *
  35.  * The GMA965 is slightly different; the backlight control register is at
  36.  * offset 0x00061250 in its PCI memory space (first 512K in the 1M region):
  37.  *  - bits 0-15 represent the backlight value
  38.  *  - bits 16-31 hold the max backlight value
  39.  *  - bit 30 indicates legacy mode is in use when set
  40.  *
  41.  *
  42.  * For BOTH cards, the register for the backlight value is at offset 0x00061254.
  43.  *
  44.  *
  45.  * For both cards, in the code below, max value and current value are expressed
  46.  * on 15 bits; the values are shifted as appropriate when appropriate.
  47.  */
  48.  
  49. #include <stdio.h>
  50. #include <sys/io.h>
  51. #include <stdlib.h>
  52. #include <string.h>
  53. #include <sys/mman.h>
  54. #include <sys/types.h>
  55. #include <sys/stat.h>
  56. #include <fcntl.h>
  57. #include <unistd.h>
  58.  
  59. #include <syslog.h>
  60.  
  61. #include <errno.h>
  62.  
  63. #include <pci/pci.h>
  64.  
  65. #include "../pommed.h"
  66. #include "../conffile.h"
  67. #include "../lcd_backlight.h"
  68. #include "../dbus.h"
  69.  
  70.  
  71. static unsigned int GMA950_BACKLIGHT_MAX;
  72.  
  73. static int fd = -1;
  74. static char *memory = NULL;
  75. static char sysfs_resource[64];
  76. static long length = 0;
  77.  
  78. #define REGISTER_OFFSET           0x00061254
  79.  
  80. #define GMA950_LEGACY_MODE        (1 << 16)
  81. #define GMA950_CONTROL_REGISTER   0x00061254
  82.  
  83. #define GMA965_LEGACY_MODE        (1 << 30)
  84. #define GMA965_CONTROL_REGISTER   0x00061250
  85.  
  86. static inline unsigned int
  87. readl(const volatile void *addr)
  88. {
  89.   return *(volatile unsigned int*) addr;
  90. }
  91.  
  92. static inline void
  93. writel(unsigned int b, volatile void *addr)
  94. {
  95.   *(volatile unsigned int*) addr = b;
  96. }
  97.  
  98. #define INREG(addr)     readl(memory+addr)
  99. #define OUTREG(addr,val)    writel(val, memory+addr)
  100.  
  101.  
  102. static unsigned int
  103. gma950_backlight_get(void)
  104. {
  105.   return (INREG(REGISTER_OFFSET) >> 1) & 0x7fff;
  106. }
  107.  
  108. static unsigned int
  109. gma950_backlight_get_max(void)
  110. {
  111.   return (INREG(REGISTER_OFFSET) >> 17);
  112. }
  113.  
  114. static void
  115. gma950_backlight_set(unsigned int value)
  116. {
  117.   OUTREG(REGISTER_OFFSET, (GMA950_BACKLIGHT_MAX << 17) | (value << 1));
  118. }
  119.  
  120.  
  121. static int
  122. gma950_backlight_map(void)
  123. {
  124.   return 0;
  125. }
  126.  
  127. static void
  128. gma950_backlight_unmap(void)
  129. {
  130. }
  131.  
  132.  
  133. void
  134. gma950_backlight_step(int dir)
  135. {
  136.  
  137. }
  138.  
  139.  
  140. void
  141. gma950_backlight_toggle(int lvl)
  142. {
  143.  
  144. }
  145.  
  146.  
  147. /*
  148.  * We are hardware-dependent for GMA950_BACKLIGHT_MAX,
  149.  * so here _fix_config() is static and called at probe time.
  150.  */
  151. static void
  152. gma950_backlight_fix_config(void)
  153. {
  154.  
  155. }
  156.  
  157.  
  158. #define PCI_ID_VENDOR_INTEL      0x8086
  159. #define PCI_ID_PRODUCT_GMA950    0x27A2
  160. #define PCI_ID_PRODUCT_GMA965    0x2A02
  161.  
  162. /* Look for an Intel GMA950 or GMA965 */
  163. int
  164. gma950_backlight_probe(void)
  165. {
  166.   return 0;
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement