All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pavel Machek <pavel@suse.cz>
To: acpi@phobos.fachschaften.tu-muenchen.de, andrew.grover@intel.com,
	kernel list <linux-kernel@vger.kernel.org>
Subject: Lid support for ACPI
Date: Mon, 23 Apr 2001 10:45:09 +0200	[thread overview]
Message-ID: <20010423104509.A2198@bug.ucw.cz> (raw)

Hi!

Here's lid support for ACPI, please apply.

								Pavel
--- clean/drivers/acpi/power.c	Wed Jan 31 16:14:33 2001
+++ linux/drivers/acpi/power.c	Sun Apr 22 23:02:25 2001
@@ -30,11 +30,11 @@
 int acpi_cmbatt_init(void);
 int acpi_cmbatt_terminate(void);
 
-/* ACPI-specific defines */
-#define ACPI_AC_ADAPTER_HID	"ACPI0003"
-
 static int ac_count = 0;
+static int lid_count = 0;
 static ACPI_HANDLE ac_handle = 0;
+static ACPI_HANDLE lid_handle = 0;
+
 
 /*
  * We found a device with the correct HID
@@ -60,11 +60,28 @@
 	}
 
 	printk(KERN_INFO "AC Adapter: found\n");
-
 	ac_handle = handle;
-
 	ac_count++;
+	return AE_OK;
+}
 
+static ACPI_STATUS
+acpi_found_lid(ACPI_HANDLE handle, u32 level, void *ctx, void **value)
+{
+	ACPI_DEVICE_INFO	info;
+
+	if (lid_count > 0) {
+		printk(KERN_ERR "Lid: more than one!\n");
+		return (AE_OK);
+	}
+
+	if (!(info.valid & ACPI_VALID_STA)) {
+		printk(KERN_ERR "Lid: _STA invalid\n");
+	}
+
+	printk(KERN_INFO "Lid: found\n");
+	lid_handle = handle;
+	lid_count++;
 	return AE_OK;
 }
 
@@ -101,23 +118,54 @@
 	return len;
 }
 
+static int
+proc_read_lid_status(char *page, char **start, off_t off,
+		     int count, int *eof, void *data)
+{
+	ACPI_OBJECT obj;
+	ACPI_BUFFER buf;
+
+	char *p = page;
+	int len;
+
+	buf.length = sizeof(obj);
+	buf.pointer = &obj;
+	if (!ACPI_SUCCESS(acpi_evaluate_object(lid_handle, "_LID", NULL, &buf))
+		|| obj.type != ACPI_TYPE_INTEGER) {
+		p += sprintf(p, "Could not read lid status\n");
+		goto end;
+	}
+
+	if (obj.integer.value)
+		p += sprintf(p, "open\n");
+	else
+		p += sprintf(p, "closed\n");
+
+end:
+	len = (p - page);
+	if (len <= off+count) *eof = 1;
+	*start = page + off;
+	len -= off;
+	if (len>count) len = count;
+	if (len<0) len = 0;
+	return len;
+}
+
 int
 acpi_power_init(void)
 {
-	acpi_get_devices(ACPI_AC_ADAPTER_HID, 
-			acpi_found_ac_adapter,
-			NULL,
-			NULL);
+	acpi_get_devices("ACPI0003", acpi_found_ac_adapter, NULL, NULL);
+	acpi_get_devices("PNP0C0D", acpi_found_lid, NULL, NULL);
 
 	if (!proc_mkdir("power", NULL))
-		return 0;
+		return -EBUSY;
 
-	if (ac_handle) {
-		create_proc_read_entry("power/ac", 0, NULL,
-			proc_read_ac_adapter_status, NULL);
-	}
+	if (ac_handle)
+		create_proc_read_entry("power/ac", 0, NULL, proc_read_ac_adapter_status, NULL);
+	if (lid_handle)
+		create_proc_read_entry("power/lid", 0, NULL, proc_read_lid_status, NULL);
 
 	acpi_cmbatt_init();
 
 	return 0;
 }
@@ -127,9 +176,8 @@
 {
 	acpi_cmbatt_terminate();
 
-	if (ac_handle) {
-		remove_proc_entry("power/ac", NULL);
-	}
+	if (ac_handle) remove_proc_entry("power/ac", NULL);
+	if (lid_handle) remove_proc_entry("power/lid", NULL);
 
 	remove_proc_entry("power", NULL);
 

-- 
I'm pavel@ucw.cz. "In my country we have almost anarchy and I don't care."
Panos Katsaloulis describing me w.r.t. patents at discuss@linmodems.org

             reply	other threads:[~2001-04-25 12:26 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-04-23  8:45 Pavel Machek [this message]
  -- strict thread matches above, loose matches on Subject: below --
2001-04-25 17:23 Lid support for ACPI Grover, Andrew
2001-04-25 20:22 ` Pavel Machek
2001-04-25 22:13 ` Pavel Machek
2001-04-27 17:08 ` Michael K. Johnson
2001-04-29  1:42   ` Pavel Machek
2001-04-25 20:54 Grover, Andrew
2001-04-30  5:00 Grover, Andrew

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20010423104509.A2198@bug.ucw.cz \
    --to=pavel@suse.cz \
    --cc=acpi@phobos.fachschaften.tu-muenchen.de \
    --cc=andrew.grover@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.