From patchwork Sat Sep 20 11:19:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Noever X-Patchwork-Id: 4941221 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 DAAD4BEEA5 for ; Sat, 20 Sep 2014 11:20:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F33F6201F4 for ; Sat, 20 Sep 2014 11:20:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1A10820200 for ; Sat, 20 Sep 2014 11:20:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755159AbaITLUT (ORCPT ); Sat, 20 Sep 2014 07:20:19 -0400 Received: from mail-qa0-f46.google.com ([209.85.216.46]:63298 "EHLO mail-qa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755094AbaITLUS (ORCPT ); Sat, 20 Sep 2014 07:20:18 -0400 Received: by mail-qa0-f46.google.com with SMTP id f12so3614271qad.19 for ; Sat, 20 Sep 2014 04:20:17 -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=g9gTMwVmpymTxvCLZCv+RTUSLLSWxWa+Op8Hdi5HmKk=; b=LXIcc/EI84+WQmxsd3dX6gOEjhHhUXOE11LLMVU0uysJ/INu5VarpJjDD80i9mwd/H wgetQjlosfCc8Lvc3JuiQ0nEu4CbavY/wy0lJ4JQ1US/W+0NN8fo44Plgyf0L4+a3wW6 l3xC96bFRkLqLN7NPa6Do/89fenYL4KXxKl1i2JwUtgUXlSb+3XyfnCRBdADYJIepEQs wqWE7drrTwdW/8NuwrT8hE5uF0YjAipcf24qjG+bJZucM4dqKMzVa1QRVEMvhtB6FOaq OLxaxiN/RQHyHXiPPWIM0kFzd7zTBOAcJvM6ajboos6utdXbjMJ2vuI7cqTbUia2WuZN bc2A== X-Received: by 10.229.84.133 with SMTP id j5mr16240415qcl.14.1411212017388; Sat, 20 Sep 2014 04:20:17 -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.15 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 20 Sep 2014 04:20:16 -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 2/3] ACPI: Disable smart battery manager on Apple Date: Sat, 20 Sep 2014 13:19:46 +0200 Message-Id: <5ff86f5736bfc9f6f638c664d33a8e13e1556e56.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 Touching the smart battery manager at all on Apple hardware appears to make it unhappy - unplugging the AC adapter triggers accesses that hang the controller for several minutes. Quirk it out via DMI in order to avoid this. Compensate by changing battery presence if we fail to communicate with the battery. Signed-off-by: Matthew Garrett Signed-off-by: Andreas Noever --- drivers/acpi/sbs.c | 51 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c index b1df4ee..32aecea 100644 --- a/drivers/acpi/sbs.c +++ b/drivers/acpi/sbs.c @@ -35,6 +35,7 @@ #include #include #include +#include #include "sbshc.h" #include "battery.h" @@ -61,6 +62,8 @@ static unsigned int cache_time = 1000; module_param(cache_time, uint, 0644); MODULE_PARM_DESC(cache_time, "cache time in milliseconds"); +static bool sbs_manager_broken; + #define MAX_SBS_BAT 4 #define ACPI_SBS_BLOCK_MAX 32 @@ -494,16 +497,21 @@ static int acpi_battery_read(struct acpi_battery *battery) ACPI_SBS_MANAGER, 0x01, (u8 *)&state, 2); } else if (battery->id == 0) battery->present = 1; + if (result || !battery->present) return result; if (saved_present != battery->present) { battery->update_time = 0; result = acpi_battery_get_info(battery); - if (result) + if (result) { + battery->present = 0; return result; + } } result = acpi_battery_get_state(battery); + if (result) + battery->present = 0; return result; } @@ -535,6 +543,7 @@ static int acpi_battery_add(struct acpi_sbs *sbs, int id) result = power_supply_register(&sbs->device->dev, &battery->bat); if (result) goto end; + result = device_create_file(battery->bat.dev, &alarm_attr); if (result) goto end; @@ -613,12 +622,31 @@ static void acpi_sbs_callback(void *context) } } +static int disable_sbs_manager(const struct dmi_system_id *d) +{ + sbs_manager_broken = true; + return 0; +} + +static struct dmi_system_id acpi_sbs_dmi_table[] = { + { + .callback = disable_sbs_manager, + .ident = "Apple", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc.") + }, + }, + { }, +}; + static int acpi_sbs_add(struct acpi_device *device) { struct acpi_sbs *sbs; int result = 0; int id; + dmi_check_system(acpi_sbs_dmi_table); + sbs = kzalloc(sizeof(struct acpi_sbs), GFP_KERNEL); if (!sbs) { result = -ENOMEM; @@ -637,14 +665,21 @@ static int acpi_sbs_add(struct acpi_device *device) if (result && result != -ENODEV) goto end; - result = acpi_manager_get_info(sbs); - if (!result) { - sbs->manager_present = 1; - for (id = 0; id < MAX_SBS_BAT; ++id) - if ((sbs->batteries_supported & (1 << id))) - acpi_battery_add(sbs, id); - } else + result = 0; + + if (!sbs_manager_broken) { + result = acpi_manager_get_info(sbs); + if (!result) { + sbs->manager_present = 0; + for (id = 0; id < MAX_SBS_BAT; ++id) + if ((sbs->batteries_supported & (1 << id))) + acpi_battery_add(sbs, id); + } + } + + if (!sbs->manager_present) acpi_battery_add(sbs, 0); + acpi_smbus_register_callback(sbs->hc, acpi_sbs_callback, sbs); end: if (result)