2 * Copyright © 2009 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Zhenyu Wang <zhenyu.z.wang@intel.com>
32 #include <pciaccess.h>
38 #include <sys/types.h>
41 #include "intel_reg.h"
42 #include "intel_bios.h"
43 #include "intel_chipset.h"
51 #define ACPI_BUTTON "/proc/acpi/button/"
52 #define ACPI_LID "/proc/acpi/button/lid/"
54 static int i830_lvds_acpi_lid_state(void)
59 struct dirent *lid_dent;
62 enum lid_status ret = LID_UNKNOWN;
64 button_dir = opendir(ACPI_BUTTON);
65 /* If acpi button driver is not loaded, bypass ACPI check method */
66 if (button_dir == NULL)
70 lid_dir = opendir(ACPI_LID);
72 /* no acpi lid object found */
77 lid_dent = readdir(lid_dir);
78 if (lid_dent == NULL) {
83 if (strcmp(lid_dent->d_name, ".") &&
84 strcmp(lid_dent->d_name, "..")) {
88 state_name = malloc(strlen(ACPI_LID) + strlen(lid_dent->d_name) + 7);
89 memset(state_name, 0, strlen(ACPI_LID) + strlen(lid_dent->d_name) + 7);
90 strcat(state_name, ACPI_LID);
91 strcat(state_name, lid_dent->d_name);
92 strcat(state_name, "/state");
96 if ((fd = open(state_name, O_RDONLY)) == -1) {
101 if (read(fd, state, 64) == -1) {
106 if (strstr(state, "open"))
108 else if (strstr(state, "closed"))
110 else /* "unsupported" */
117 int main(int argc, char **argv)
121 intel_mmio_use_pci_bar(intel_get_pci_device());
124 swf14 = INREG(SWF14);
126 printf("Intel LVDS Lid status:\n");
127 printf("\tSWF14(0x%x) : %s\n", swf14,
128 swf14 & SWF14_LID_SWITCH_EN ? "close" : "open");
130 acpi_lid = i830_lvds_acpi_lid_state();
133 printf("\tACPI Lid state : unknown\n");
136 printf("\tACPI Lid state : open\n");
139 printf("\tACPI Lid state : close\n");