2006-11-26 11:13:41 -07:00
|
|
|
#ifdef HAVE_XORG_CONFIG_H
|
|
|
|
#include "xorg-config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "os.h"
|
|
|
|
#include "xf86.h"
|
|
|
|
#include "xf86Priv.h"
|
|
|
|
#define XF86_OS_PRIVS
|
|
|
|
#include "xf86_OSproc.h"
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/un.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
#define ACPI_SOCKET "/var/run/acpid.socket"
|
|
|
|
|
|
|
|
#define ACPI_VIDEO_NOTIFY_SWITCH 0x80
|
|
|
|
#define ACPI_VIDEO_NOTIFY_PROBE 0x81
|
|
|
|
#define ACPI_VIDEO_NOTIFY_CYCLE 0x82
|
|
|
|
#define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
|
|
|
|
#define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
#define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85
|
|
|
|
#define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
|
|
|
|
#define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
|
|
|
|
#define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
|
|
|
|
#define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
#define ACPI_VIDEO_HEAD_INVALID (~0u - 1)
|
|
|
|
#define ACPI_VIDEO_HEAD_END (~0u)
|
|
|
|
|
|
|
|
static void lnxCloseACPI(void);
|
|
|
|
static pointer ACPIihPtr = NULL;
|
|
|
|
PMClose lnxACPIOpen(void);
|
|
|
|
|
|
|
|
/* in milliseconds */
|
|
|
|
#define ACPI_REOPEN_DELAY 1000
|
|
|
|
|
|
|
|
static CARD32
|
|
|
|
lnxACPIReopen(OsTimerPtr timer, CARD32 time, pointer arg)
|
|
|
|
{
|
|
|
|
if (lnxACPIOpen()) {
|
2012-06-10 07:21:05 -06:00
|
|
|
TimerFree(timer);
|
|
|
|
return 0;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return ACPI_REOPEN_DELAY;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define LINE_LENGTH 80
|
|
|
|
|
|
|
|
static int
|
2012-06-10 07:21:05 -06:00
|
|
|
lnxACPIGetEventFromOs(int fd, pmEvent * events, int num)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
char ev[LINE_LENGTH];
|
|
|
|
int n;
|
|
|
|
|
|
|
|
memset(ev, 0, LINE_LENGTH);
|
|
|
|
|
|
|
|
do {
|
2012-06-10 07:21:05 -06:00
|
|
|
n = read(fd, ev, LINE_LENGTH);
|
2006-11-26 11:13:41 -07:00
|
|
|
} while ((n == -1) && (errno == EAGAIN || errno == EINTR));
|
|
|
|
|
|
|
|
if (n <= 0) {
|
2012-06-10 07:21:05 -06:00
|
|
|
lnxCloseACPI();
|
|
|
|
TimerSet(NULL, 0, ACPI_REOPEN_DELAY, lnxACPIReopen, NULL);
|
|
|
|
return 0;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2008-11-02 08:26:08 -07:00
|
|
|
/* FIXME: this only processes the first read ACPI event & might break
|
|
|
|
* with interrupted reads. */
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
/* Check that we have a video event */
|
2008-11-02 08:26:08 -07:00
|
|
|
if (!strncmp(ev, "video", 5)) {
|
2012-06-10 07:21:05 -06:00
|
|
|
char *video = NULL;
|
|
|
|
char *GFX = NULL;
|
|
|
|
char *notify = NULL;
|
|
|
|
char *data = NULL; /* doesn't appear to be used in the kernel */
|
|
|
|
unsigned long int notify_l, data_l;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
video = strtok(ev, " ");
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
GFX = strtok(NULL, " ");
|
2006-11-26 11:13:41 -07:00
|
|
|
#if 0
|
2012-06-10 07:21:05 -06:00
|
|
|
ErrorF("GFX: %s\n", GFX);
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
notify = strtok(NULL, " ");
|
|
|
|
notify_l = strtoul(notify, NULL, 16);
|
2006-11-26 11:13:41 -07:00
|
|
|
#if 0
|
2012-06-10 07:21:05 -06:00
|
|
|
ErrorF("notify: 0x%lx\n", notify_l);
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
data = strtok(NULL, " ");
|
|
|
|
data_l = strtoul(data, NULL, 16);
|
2006-11-26 11:13:41 -07:00
|
|
|
#if 0
|
2012-06-10 07:21:05 -06:00
|
|
|
ErrorF("data: 0x%lx\n", data_l);
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/* Differentiate between events */
|
|
|
|
switch (notify_l) {
|
|
|
|
case ACPI_VIDEO_NOTIFY_SWITCH:
|
|
|
|
case ACPI_VIDEO_NOTIFY_CYCLE:
|
|
|
|
case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT:
|
|
|
|
case ACPI_VIDEO_NOTIFY_PREV_OUTPUT:
|
|
|
|
events[0] = XF86_APM_CAPABILITY_CHANGED;
|
|
|
|
return 1;
|
|
|
|
case ACPI_VIDEO_NOTIFY_PROBE:
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static pmWait
|
|
|
|
lnxACPIConfirmEventToOs(int fd, pmEvent event)
|
|
|
|
{
|
|
|
|
/* No ability to send back to the kernel in ACPI */
|
|
|
|
switch (event) {
|
|
|
|
default:
|
2012-06-10 07:21:05 -06:00
|
|
|
return PM_NONE;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PMClose
|
|
|
|
lnxACPIOpen(void)
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
int fd;
|
2006-11-26 11:13:41 -07:00
|
|
|
struct sockaddr_un addr;
|
|
|
|
int r = -1;
|
2010-07-27 13:02:24 -06:00
|
|
|
static int warned = 0;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
DebugF("ACPI: OSPMOpen called\n");
|
2006-11-26 11:13:41 -07:00
|
|
|
if (ACPIihPtr || !xf86Info.pmFlag)
|
2012-06-10 07:21:05 -06:00
|
|
|
return NULL;
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
DebugF("ACPI: Opening device\n");
|
2006-11-26 11:13:41 -07:00
|
|
|
if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) > -1) {
|
2012-06-10 07:21:05 -06:00
|
|
|
memset(&addr, 0, sizeof(addr));
|
|
|
|
addr.sun_family = AF_UNIX;
|
|
|
|
strcpy(addr.sun_path, ACPI_SOCKET);
|
|
|
|
if ((r = connect(fd, (struct sockaddr *) &addr, sizeof(addr))) == -1) {
|
|
|
|
if (!warned)
|
|
|
|
xf86MsgVerb(X_WARNING, 3, "Open ACPI failed (%s) (%s)\n",
|
|
|
|
ACPI_SOCKET, strerror(errno));
|
|
|
|
warned = 1;
|
|
|
|
shutdown(fd, 2);
|
|
|
|
close(fd);
|
|
|
|
return NULL;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
xf86PMGetEventFromOs = lnxACPIGetEventFromOs;
|
|
|
|
xf86PMConfirmEventToOs = lnxACPIConfirmEventToOs;
|
2012-06-10 07:21:05 -06:00
|
|
|
ACPIihPtr = xf86AddGeneralHandler(fd, xf86HandlePMEvents, NULL);
|
|
|
|
xf86MsgVerb(X_INFO, 3, "Open ACPI successful (%s)\n", ACPI_SOCKET);
|
2010-07-27 13:02:24 -06:00
|
|
|
warned = 0;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
return lnxCloseACPI;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
lnxCloseACPI(void)
|
|
|
|
{
|
|
|
|
int fd;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
DebugF("ACPI: Closing device\n");
|
2006-11-26 11:13:41 -07:00
|
|
|
if (ACPIihPtr) {
|
2012-06-10 07:21:05 -06:00
|
|
|
fd = xf86RemoveGeneralHandler(ACPIihPtr);
|
|
|
|
shutdown(fd, 2);
|
|
|
|
close(fd);
|
|
|
|
ACPIihPtr = NULL;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|