From: andreas.noever@gmail.com
To: rjw@rjwysocki.net
Cc: lenb@kernel.org, robert.moore@intel.com, lv.zheng@intel.com,
linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.or,
linux-pci@vger.kernel.org, bhelgaas@google.com,
matthew.garrett@nebula.com,
Andreas Noever <andreas.noever@gmail.com>
Subject: [PATCH v2 1/3] ACPI: Don't assume the existence of an SBS charger
Date: Sat, 20 Sep 2014 13:19:45 +0200 [thread overview]
Message-ID: <291e876fa0a2c963b948e22a7bce963e63e6150a.1411211725.git.andreas.noever@gmail.com> (raw)
In-Reply-To: <cover.1411211725.git.andreas.noever@gmail.com>
In-Reply-To: <cover.1411211725.git.andreas.noever@gmail.com>
From: Matthew Garrett <matthew.garrett@nebula.com>
From: Matthew Garrett <matthew.garrett@nebula.com>
Apple hardware continues to expose an ACPI AC charger even when using
SBS to report battery state. The charger status byte returns all 0s in
this case. Since the spec requires that bit 4 be 1 at all times, assume
that there's not really a charger if it's set to zero.
Signed-off-by: Matthew Garrett <matthew.garrett@nebula.com>
Signed-off-by: Andreas Noever <andreas.noever@gmail.com>
---
drivers/acpi/sbs.c | 29 ++++++++++++++++++++++-------
1 file changed, 22 insertions(+), 7 deletions(-)
diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
index 366ca40..b1df4ee 100644
--- a/drivers/acpi/sbs.c
+++ b/drivers/acpi/sbs.c
@@ -109,6 +109,7 @@ struct acpi_sbs {
u8 batteries_supported:4;
u8 manager_present:1;
u8 charger_present:1;
+ u8 charger_exists:1;
};
#define to_acpi_sbs(x) container_of(x, struct acpi_sbs, charger)
@@ -429,9 +430,19 @@ static int acpi_ac_get_present(struct acpi_sbs *sbs)
result = acpi_smbus_read(sbs->hc, SMBUS_READ_WORD, ACPI_SBS_CHARGER,
0x13, (u8 *) & status);
- if (!result)
- sbs->charger_present = (status >> 15) & 0x1;
- return result;
+
+ if (result)
+ return result;
+
+ /*
+ * The spec requires that bit 4 always be 1. If it's not set, assume
+ * that the implementation doesn't support an SBS charger
+ */
+ if (!(status >> 4) & 0x1)
+ return -ENODEV;
+
+ sbs->charger_present = (status >> 15) & 0x1;
+ return 0;
}
static ssize_t acpi_battery_alarm_show(struct device *dev,
@@ -554,6 +565,7 @@ static int acpi_charger_add(struct acpi_sbs *sbs)
if (result)
goto end;
+ sbs->charger_exists = 1;
sbs->charger.name = "sbs-charger";
sbs->charger.type = POWER_SUPPLY_TYPE_MAINS;
sbs->charger.properties = sbs_ac_props;
@@ -580,9 +592,12 @@ static void acpi_sbs_callback(void *context)
struct acpi_battery *bat;
u8 saved_charger_state = sbs->charger_present;
u8 saved_battery_state;
- acpi_ac_get_present(sbs);
- if (sbs->charger_present != saved_charger_state)
- kobject_uevent(&sbs->charger.dev->kobj, KOBJ_CHANGE);
+
+ if (sbs->charger_exists) {
+ acpi_ac_get_present(sbs);
+ if (sbs->charger_present != saved_charger_state)
+ kobject_uevent(&sbs->charger.dev->kobj, KOBJ_CHANGE);
+ }
if (sbs->manager_present) {
for (id = 0; id < MAX_SBS_BAT; ++id) {
@@ -619,7 +634,7 @@ static int acpi_sbs_add(struct acpi_device *device)
device->driver_data = sbs;
result = acpi_charger_add(sbs);
- if (result)
+ if (result && result != -ENODEV)
goto end;
result = acpi_manager_get_info(sbs);
--
2.1.0
next prev parent reply other threads:[~2014-09-20 11:20 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-20 11:19 [PATCH v2 0/3] ACPI: Improve behaviour on Apple hardware andreas.noever
2014-09-20 11:19 ` andreas.noever [this message]
2014-09-20 11:19 ` [PATCH v2 2/3] ACPI: Disable smart battery manager on Apple andreas.noever
2014-09-20 11:19 ` [PATCH v2 3/3] ACPI: Support _OSI("Darwin") correctly andreas.noever
2014-09-21 0:22 ` [PATCH v2 0/3] ACPI: Improve behaviour on Apple hardware Rafael J. Wysocki
2014-09-25 23:45 ` Rafael J. Wysocki
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=291e876fa0a2c963b948e22a7bce963e63e6150a.1411211725.git.andreas.noever@gmail.com \
--to=andreas.noever@gmail.com \
--cc=bhelgaas@google.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.or \
--cc=linux-pci@vger.kernel.org \
--cc=lv.zheng@intel.com \
--cc=matthew.garrett@nebula.com \
--cc=rjw@rjwysocki.net \
--cc=robert.moore@intel.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).