All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Garrett <mjg59@srcf.ucam.org>
To: linux-pm@lists.osdl.org, linux-acpi@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH, RFC] [2/3] ACPI support for generic in-kernel AC status
Date: Wed, 8 Feb 2006 13:03:34 +0000	[thread overview]
Message-ID: <20060208130334.GA25659@srcf.ucam.org> (raw)
In-Reply-To: <20060208125753.GA25562@srcf.ucam.org>

The included patch adds support for the generic in-kernel AC status 
code. Each AC adapter device is added to a list - when queried, if at 
least one claims to be online then we assume that the system is on AC.

Signed-Off-By: Matthew Garrett <mjg59@srcf.ucam.org>

diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c
index 61f95ce..aa2d9b9 100644
--- a/drivers/acpi/ac.c
+++ b/drivers/acpi/ac.c
@@ -29,6 +29,7 @@
 #include <linux/types.h>
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
+#include <linux/pm.h>
 #include <acpi/acpi_bus.h>
 #include <acpi/acpi_drivers.h>
 
@@ -67,8 +68,11 @@ static struct acpi_driver acpi_ac_driver
 struct acpi_ac {
 	acpi_handle handle;
 	unsigned long state;
+	struct list_head entry;
 };
 
+static struct list_head ac_adapter_list;
+
 static struct file_operations acpi_ac_fops = {
 	.open = acpi_ac_open_fs,
 	.read = seq_read,
@@ -255,6 +259,8 @@ static int acpi_ac_add(struct acpi_devic
 		goto end;
 	}
 
+	list_add(&ac->entry, &ac_adapter_list);
+
 	printk(KERN_INFO PREFIX "%s [%s] (%s)\n",
 	       acpi_device_name(device), acpi_device_bid(device),
 	       ac->state ? "on-line" : "off-line");
@@ -288,17 +294,34 @@ static int acpi_ac_remove(struct acpi_de
 
 	acpi_ac_remove_fs(device);
 
+	list_del(&ac->entry);
+
 	kfree(ac);
 
 	return_VALUE(0);
 }
 
+static int acpi_ac_online_status(void)
+{
+	struct acpi_ac *adapter;
+	
+	list_for_each_entry(adapter, &ac_adapter_list, entry) {
+		acpi_ac_get_state(adapter);
+		if (adapter->state)
+			return 1;
+	}
+
+	return 0;
+}
+
 static int __init acpi_ac_init(void)
 {
 	int result = 0;
 
 	ACPI_FUNCTION_TRACE("acpi_ac_init");
 
+	INIT_LIST_HEAD(&ac_adapter_list);
+
 	acpi_ac_dir = proc_mkdir(ACPI_AC_CLASS, acpi_root_dir);
 	if (!acpi_ac_dir)
 		return_VALUE(-ENODEV);
@@ -310,6 +333,8 @@ static int __init acpi_ac_init(void)
 		return_VALUE(-ENODEV);
 	}
 
+	pm_set_ac_status(acpi_ac_online_status);
+
 	return_VALUE(0);
 }
 
@@ -317,6 +342,8 @@ static void __exit acpi_ac_exit(void)
 {
 	ACPI_FUNCTION_TRACE("acpi_ac_exit");
 
+	pm_set_ac_status(NULL);
+
 	acpi_bus_unregister_driver(&acpi_ac_driver);
 
 	remove_proc_entry(ACPI_AC_CLASS, acpi_root_dir);

-- 
Matthew Garrett | mjg59@srcf.ucam.org

  reply	other threads:[~2006-02-08 13:03 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-08 12:57 [PATCH, RFC] [1/3] Generic in-kernel AC status Matthew Garrett
2006-02-08 13:03 ` Matthew Garrett [this message]
2006-02-08 13:04 ` Matthew Garrett
2006-02-08 13:05   ` [PATCH, RFC] [3/3] APM support for generic " Matthew Garrett
2006-02-08 16:58   ` [linux-pm] Re: [PATCH, RFC] [1/3] Generic " Greg KH
2006-02-08 17:08     ` Matthew Garrett
2006-02-08 17:08       ` [linux-pm] " Matthew Garrett
2006-02-08 17:16       ` Greg KH
2006-02-08 17:49         ` Matthew Garrett
2006-02-09  5:46           ` Greg KH
2006-02-09  8:53       ` Gabor Gombas
2006-02-10 12:21         ` Pavel Machek
2006-02-10 12:21           ` Pavel Machek
2006-02-10 13:13           ` Gabor Gombas
2006-02-10 13:13             ` [linux-pm] " Gabor Gombas
2006-02-10 13:19             ` Matthew Garrett
2006-02-10 13:54             ` Pavel Machek
2006-02-10 13:54               ` Pavel Machek
2006-02-10 13:56               ` Gabor Gombas
2006-02-10 13:56                 ` [linux-pm] " Gabor Gombas
2006-02-08 22:25   ` Philipp Matthias Hahn
2006-02-10 12:21     ` Pavel Machek
2006-02-10  8:06 ` Stefan Seyfried
2006-02-10  8:06   ` Stefan Seyfried
2006-02-10 12:19   ` Pavel Machek
2006-02-10 12:19     ` Pavel Machek
2006-02-10 12:32     ` Stefan Seyfried
2006-02-10 12:32       ` Stefan Seyfried
2006-02-10 13:46       ` Pavel Machek
2006-02-10 13:46         ` Pavel Machek
2006-02-12 10:17         ` Jan Engelhardt
2006-02-12 11:27           ` Kyle Moffett
2006-02-14 17:44     ` Thomas Renninger
2006-02-14 17:44       ` Thomas Renninger
2006-02-14 20:17       ` Rafael J. Wysocki
2006-02-14 20:17         ` Rafael J. Wysocki
2006-02-15 12:36         ` Thomas Renninger
2006-02-15 12:36           ` Thomas Renninger
2006-02-15 12:47           ` Matthew Garrett
2006-02-15 12:47             ` Matthew Garrett
2006-02-15 15:04             ` Thomas Renninger
2006-02-16 22:44           ` Pavel Machek
2006-02-16 22:44             ` Pavel Machek
2006-02-16 22:39         ` Pavel Machek
2006-02-16 22:39           ` Pavel Machek

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=20060208130334.GA25659@srcf.ucam.org \
    --to=mjg59@srcf.ucam.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@lists.osdl.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.