From patchwork Tue Mar 11 22:20:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Garrett X-Patchwork-Id: 3814601 Return-Path: X-Original-To: patchwork-linux-acpi@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 8FBAEBF540 for ; Tue, 11 Mar 2014 22:22:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 642232020A for ; Tue, 11 Mar 2014 22:22:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2982E201B4 for ; Tue, 11 Mar 2014 22:22:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755974AbaCKWUS (ORCPT ); Tue, 11 Mar 2014 18:20:18 -0400 Received: from cavan.codon.org.uk ([93.93.128.6]:52148 "EHLO cavan.codon.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755972AbaCKWUO (ORCPT ); Tue, 11 Mar 2014 18:20:14 -0400 Received: from 209-6-207-143.c3-0.smr-ubr2.sbo-smr.ma.cable.rcn.com ([209.6.207.143] helo=localhost.lan) by cavan.codon.org.uk with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.72) (envelope-from ) id 1WNV1x-0002xq-GH; Tue, 11 Mar 2014 22:20:13 +0000 From: Matthew Garrett To: linux-acpi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, lenb@kernel.org, rjw@rjwysocki.net, Matthew Garrett Subject: [PATCH 3/3] ACPI: Don't re-select SBS battery if it's already selected Date: Tue, 11 Mar 2014 18:20:02 -0400 Message-Id: <1394576402-2910-4-git-send-email-matthew.garrett@nebula.com> X-Mailer: git-send-email 1.8.5.3 In-Reply-To: <1394576402-2910-1-git-send-email-matthew.garrett@nebula.com> References: <1394576402-2910-1-git-send-email-matthew.garrett@nebula.com> X-SA-Do-Not-Run: Yes X-SA-Exim-Connect-IP: 209.6.207.143 X-SA-Exim-Mail-From: matthew.garrett@nebula.com X-SA-Exim-Scanned: No (on cavan.codon.org.uk); SAEximRunCond expanded to false Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, 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 The existing SBS code explicitly sets the selected battery in the SBS manager regardless of whether the battery in question is already selected. This causes bus timeouts on Apple hardware. Check for this case and avoid it. Signed-off-by: Matthew Garrett --- drivers/acpi/sbs.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c index dbd4849..c386505 100644 --- a/drivers/acpi/sbs.c +++ b/drivers/acpi/sbs.c @@ -470,17 +470,25 @@ static struct device_attribute alarm_attr = { static int acpi_battery_read(struct acpi_battery *battery) { int result = 0, saved_present = battery->present; - u16 state; + u16 state, selected, desired; if (battery->sbs->manager_present) { result = acpi_smbus_read(battery->sbs->hc, SMBUS_READ_WORD, ACPI_SBS_MANAGER, 0x01, (u8 *)&state); if (!result) battery->present = state & (1 << battery->id); - state &= 0x0fff; - state |= 1 << (battery->id + 12); - acpi_smbus_write(battery->sbs->hc, SMBUS_WRITE_WORD, - ACPI_SBS_MANAGER, 0x01, (u8 *)&state, 2); + /* + * Don't switch battery if the correct one is already selected + */ + selected = state & 0xf000; + desired = 1 << (battery->id + 12); + if (selected != desired) { + state &= 0x0fff; + state |= desired; + acpi_smbus_write(battery->sbs->hc, SMBUS_WRITE_WORD, + ACPI_SBS_MANAGER, 0x01, + (u8 *)&state, 2); + } } else if (battery->id == 0) battery->present = 1; if (result || !battery->present)