~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to hw/xfree86/os-support/linux/lnx_acpi.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "X.h"
 
2
#include "os.h"
 
3
#include "xf86.h"
 
4
#include "xf86Priv.h"
 
5
#define XF86_OS_PRIVS
 
6
#include "xf86_OSproc.h"
 
7
#include <sys/ioctl.h>
 
8
#include <sys/types.h>
 
9
#include <sys/socket.h>
 
10
#include <sys/un.h>
 
11
#include <unistd.h>
 
12
#include <fcntl.h>
 
13
#include <errno.h>
 
14
 
 
15
#define ACPI_SOCKET  "/var/run/acpid.socket"
 
16
#define ACPI_EVENTS  "/proc/acpi/event"
 
17
 
 
18
#define ACPI_VIDEO_NOTIFY_SWITCH        0x80
 
19
#define ACPI_VIDEO_NOTIFY_PROBE         0x81
 
20
#define ACPI_VIDEO_NOTIFY_CYCLE         0x82
 
21
#define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT   0x83
 
22
#define ACPI_VIDEO_NOTIFY_PREV_OUTPUT   0x84
 
23
 
 
24
#define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS      0x82
 
25
#define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS        0x83
 
26
#define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS        0x84
 
27
#define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS       0x85
 
28
#define ACPI_VIDEO_NOTIFY_DISPLAY_OFF           0x86
 
29
 
 
30
#define ACPI_VIDEO_HEAD_INVALID         (~0u - 1)
 
31
#define ACPI_VIDEO_HEAD_END             (~0u)
 
32
 
 
33
static void lnxCloseACPI(void);
 
34
static pointer ACPIihPtr = NULL;
 
35
PMClose lnxACPIOpen(void);
 
36
 
 
37
#define LINE_LENGTH 80
 
38
 
 
39
static int
 
40
lnxACPIGetEventFromOs(int fd, pmEvent *events, int num)
 
41
{
 
42
    char ev[LINE_LENGTH];
 
43
    int n;
 
44
 
 
45
    memset(ev, 0, LINE_LENGTH);
 
46
 
 
47
    n = read( fd, ev, LINE_LENGTH );
 
48
 
 
49
    /* Check that we have a video event */
 
50
    if (strstr(ev, "video") == ev) {
 
51
        char *video = NULL;
 
52
        char *GFX = NULL;
 
53
        char *notify = NULL;
 
54
        char *data = NULL; /* doesn't appear to be used in the kernel */
 
55
        unsigned long int notify_l, data_l;
 
56
 
 
57
        video = strtok(ev, "video");
 
58
 
 
59
        GFX = strtok(NULL, " ");
 
60
#if 0
 
61
        ErrorF("GFX: %s\n",GFX);
 
62
#endif
 
63
 
 
64
        notify = strtok(NULL, " ");
 
65
        notify_l = strtoul(notify, NULL, 16);
 
66
#if 0
 
67
        ErrorF("notify: 0x%lx\n",notify_l);
 
68
#endif
 
69
 
 
70
        data = strtok(NULL, " ");
 
71
        data_l = strtoul(data, NULL, 16);
 
72
#if 0
 
73
        ErrorF("data: 0x%lx\n",data_l);
 
74
#endif
 
75
 
 
76
        /* We currently don't differentiate between any event */
 
77
        switch (notify_l) {
 
78
                case ACPI_VIDEO_NOTIFY_SWITCH:
 
79
                        break;
 
80
                case ACPI_VIDEO_NOTIFY_PROBE:
 
81
                        break;
 
82
                case ACPI_VIDEO_NOTIFY_CYCLE:
 
83
                        break;
 
84
                case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT:
 
85
                        break;
 
86
                case ACPI_VIDEO_NOTIFY_PREV_OUTPUT:
 
87
                        break;
 
88
                default:
 
89
                        break;
 
90
        }
 
91
 
 
92
        /* Deal with all ACPI events as a capability change */
 
93
        events[0] = XF86_APM_CAPABILITY_CHANGED;
 
94
 
 
95
        return 1;
 
96
    }
 
97
    
 
98
    return 0;
 
99
}
 
100
 
 
101
static pmWait
 
102
lnxACPIConfirmEventToOs(int fd, pmEvent event)
 
103
{
 
104
    /* No ability to send back to the kernel in ACPI */
 
105
    switch (event) {
 
106
    default:
 
107
        return PM_NONE;
 
108
    }
 
109
}
 
110
 
 
111
PMClose
 
112
lnxACPIOpen(void)
 
113
{
 
114
    int fd;    
 
115
    struct sockaddr_un addr;
 
116
    int r = -1;
 
117
 
 
118
#ifdef DEBUG
 
119
    ErrorF("ACPI: OSPMOpen called\n");
 
120
#endif
 
121
    if (ACPIihPtr || !xf86Info.pmFlag)
 
122
        return NULL;
 
123
   
 
124
#ifdef DEBUG
 
125
    ErrorF("ACPI: Opening device\n");
 
126
#endif
 
127
    if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) > -1) {
 
128
        memset(&addr, 0, sizeof(addr));
 
129
        addr.sun_family = AF_UNIX;
 
130
        strcpy(addr.sun_path, ACPI_SOCKET);
 
131
        if ((r = connect(fd, (struct sockaddr*)&addr, sizeof(addr))) == -1) {
 
132
            shutdown(fd, 2);
 
133
            close(fd);
 
134
            fd = -1;
 
135
        }
 
136
    }
 
137
 
 
138
    /* acpid's socket isn't available, so try going direct */
 
139
    if (fd == -1) {
 
140
        if ((fd = open(ACPI_EVENTS, O_RDONLY)) < 0) {
 
141
            xf86MsgVerb(X_WARNING,3,"Open ACPI failed (%s) (%s)\n", ACPI_EVENTS,
 
142
                strerror(errno));
 
143
            return NULL;
 
144
        }
 
145
    }
 
146
 
 
147
    xf86PMGetEventFromOs = lnxACPIGetEventFromOs;
 
148
    xf86PMConfirmEventToOs = lnxACPIConfirmEventToOs;
 
149
    ACPIihPtr = xf86AddInputHandler(fd,xf86HandlePMEvents,NULL);
 
150
    xf86MsgVerb(X_INFO,3,"Open ACPI successful (%s)\n", (r != -1) ? ACPI_SOCKET : ACPI_EVENTS);
 
151
 
 
152
    return lnxCloseACPI;
 
153
}
 
154
 
 
155
static void
 
156
lnxCloseACPI(void)
 
157
{
 
158
    int fd;
 
159
    
 
160
#ifdef DEBUG
 
161
   ErrorF("ACPI: Closing device\n");
 
162
#endif
 
163
    if (ACPIihPtr) {
 
164
        fd = xf86RemoveInputHandler(ACPIihPtr);
 
165
        shutdown(fd, 2);
 
166
        close(fd);
 
167
        ACPIihPtr = NULL;
 
168
    }
 
169
}
 
170