From patchwork Sat Sep 20 11:19:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Noever X-Patchwork-Id: 4941191 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 807BABEEA5 for ; Sat, 20 Sep 2014 11:20:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B547F20212 for ; Sat, 20 Sep 2014 11:20:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B4053201F4 for ; Sat, 20 Sep 2014 11:20:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755133AbaITLUR (ORCPT ); Sat, 20 Sep 2014 07:20:17 -0400 Received: from mail-qg0-f45.google.com ([209.85.192.45]:38539 "EHLO mail-qg0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755094AbaITLUQ (ORCPT ); Sat, 20 Sep 2014 07:20:16 -0400 Received: by mail-qg0-f45.google.com with SMTP id q108so996589qgd.18 for ; Sat, 20 Sep 2014 04:20:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=nwE0d/7mkJyZjVok23iLGK1TawQTXLAdCPfZ1QAA+7k=; b=xuWKk1YmWRWQf66tieI0P9Xfq4sY7njJn6Py1KlzyWVhgzfR1GPpYyEw1of7CKT+YC vkgswf/EM9cxPz7fbBsWqK9Dq+YhBuarCfoPiFXt9t1BJWvsTs4gq7O2AkduFzKByzyP VZqRUJ2XqXHJ4T327uDg+/hLYXSE0mDyXnaBIbMha0CRTSnBEzPSpahtaYNy2bWkT27N 7WIdAagaGEjjGXKPckvNeJG9+0aVMsfHEfvz0ZxHOqbH0dL/F+NGfy8LfWKYebBUka9p 8CJDe0/3JMXi1GYyE4KyFo3y+i9rC7rBqIJa5heqADZJJW6qVQKgAJp8oRs5qllgijkv B9EA== X-Received: by 10.229.183.130 with SMTP id cg2mr16114043qcb.17.1411212015324; Sat, 20 Sep 2014 04:20:15 -0700 (PDT) Received: from linuxbook.fritz.box (HSI-KBW-095-208-100-070.hsi5.kabel-badenwuerttemberg.de. [95.208.100.70]) by mx.google.com with ESMTPSA id f17sm3445961qge.23.2014.09.20.04.20.13 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 20 Sep 2014 04:20:14 -0700 (PDT) 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 Subject: [PATCH v2 1/3] ACPI: Don't assume the existence of an SBS charger Date: Sat, 20 Sep 2014 13:19:45 +0200 Message-Id: <291e876fa0a2c963b948e22a7bce963e63e6150a.1411211725.git.andreas.noever@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: References: In-Reply-To: References: Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Matthew Garrett From: Matthew Garrett 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 Signed-off-by: Andreas Noever --- 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);