From patchwork Mon Mar 10 19:52:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Garrett X-Patchwork-Id: 3805591 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 83CD3BF540 for ; Mon, 10 Mar 2014 19:52:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B050D202D1 for ; Mon, 10 Mar 2014 19:52:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D7733202A1 for ; Mon, 10 Mar 2014 19:52:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753244AbaCJTw2 (ORCPT ); Mon, 10 Mar 2014 15:52:28 -0400 Received: from cavan.codon.org.uk ([93.93.128.6]:59852 "EHLO cavan.codon.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752954AbaCJTw1 (ORCPT ); Mon, 10 Mar 2014 15:52:27 -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 1WN6FK-0004Le-4I; Mon, 10 Mar 2014 19:52:22 +0000 From: Matthew Garrett To: linux-acpi@vger.kernel.org Cc: lenb@kernel.org, rjw@rjwysocki.net, Matthew Garrett Subject: [PATCH] ACPI: Don't re-select SBS battery if it's already selected Date: Mon, 10 Mar 2014 15:52:14 -0400 Message-Id: <1394481134-1723-1-git-send-email-matthew.garrett@nebula.com> X-Mailer: git-send-email 1.8.5.3 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=ham 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)