From patchwork Fri Sep 9 02:10:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 9322341 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 63433607D3 for ; Fri, 9 Sep 2016 02:10:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E11C29A9B for ; Fri, 9 Sep 2016 02:10:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3EA2329AB9; Fri, 9 Sep 2016 02:10:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95EDB29A9B for ; Fri, 9 Sep 2016 02:10:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751667AbcIICKG (ORCPT ); Thu, 8 Sep 2016 22:10:06 -0400 Received: from bh-25.webhostbox.net ([208.91.199.152]:35270 "EHLO bh-25.webhostbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751657AbcIICKF (ORCPT ); Thu, 8 Sep 2016 22:10:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=roeck-us.net; s=default; h=Message-Id:Date:Subject:Cc:To:From; bh=31xQfRJRvvgEAD8u+97Nerjiy9sbMyS6zGh/jzUWiaQ=; b=I8yoInILQDXcdzjR5D5WLmeG9Z mnKHzYIhfmyglShh0gCpqcWu/pBvLK3aJuDqzq5xZzvUKRfC/W6JzZe2SNoNCjTEnXhzaBkRp5mz5 N9yOWBl+s8yJKzV9WsrIMCoiu3BJNWRj1wTIDlymPhgzdpHbxqEr8gKk9dKzB0eJzjFxXL5Sid8O/ 6j0rrY54/cUbJORPFN90q/TOSBLMzXwspLmKdj1xHnxdJ8MRJHEN6B3uhEt5KdLZIw8Q+n1n7nsg6 6g0iheGUg0PDS1QQshsacIJM0/48XaTMxn89SoxU7D1gMBQob3xK+2Witq8Bf8m7OodU1BJnF85a0 fFCxkyFg==; Received: from 108-223-40-66.lightspeed.sntcca.sbcglobal.net ([108.223.40.66]:42160 helo=localhost) by bh-25.webhostbox.net with esmtpa (Exim 4.86_1) (envelope-from ) id 1biBGS-002see-Bc; Fri, 09 Sep 2016 02:10:01 +0000 From: Guenter Roeck To: Sebastian Reichel Cc: Dmitry Eremin-Solenikov , David Woodhouse , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Guenter Roeck , Brian Norris Subject: [PATCH] sbs-battery: make writes to ManufacturerAccess optional Date: Thu, 8 Sep 2016 19:10:00 -0700 Message-Id: <1473387000-13646-1-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 2.5.0 X-Authenticated_sender: guenter@roeck-us.net X-OutGoing-Spam-Status: No, score=-1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bh-25.webhostbox.net X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - roeck-us.net X-Get-Message-Sender-Via: bh-25.webhostbox.net: authenticated_id: guenter@roeck-us.net X-Authenticated-Sender: bh-25.webhostbox.net: guenter@roeck-us.net X-Source: X-Source-Args: X-Source-Dir: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP According to the Smart Battery Data Specification, the use of ManufacturerAcess (register 0x0) is implementation-defined. It appears that some batteries use writes to this register in order to implement certain functionality, but others may simply NAK all writes to it. As a result, write failures to ManufacturerAccess should not be used as an indicator of battery presence, nor as a failure to enter sleep mode. The failed write access was seen with SANYO AP13J3K. Cc: Brian Norris Signed-off-by: Guenter Roeck --- drivers/power/sbs-battery.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/drivers/power/sbs-battery.c b/drivers/power/sbs-battery.c index 768b9fcb58ea..5621b8c048cf 100644 --- a/drivers/power/sbs-battery.c +++ b/drivers/power/sbs-battery.c @@ -313,21 +313,22 @@ static int sbs_get_battery_presence_and_health( return ret; } - /* Write to ManufacturerAccess with - * ManufacturerAccess command and then - * read the status */ - ret = sbs_write_word_data(client, sbs_data[REG_MANUFACTURER_DATA].addr, - MANUFACTURER_ACCESS_STATUS); + /* + * Write to ManufacturerAccess with ManufacturerAccess command + * and then read the status. Do not check for error on the write + * since not all batteries implement write access to this command, + * while others mandate it. + */ + sbs_write_word_data(client, sbs_data[REG_MANUFACTURER_DATA].addr, + MANUFACTURER_ACCESS_STATUS); + + ret = sbs_read_word_data(client, sbs_data[REG_MANUFACTURER_DATA].addr); if (ret < 0) { if (psp == POWER_SUPPLY_PROP_PRESENT) val->intval = 0; /* battery removed */ return ret; } - ret = sbs_read_word_data(client, sbs_data[REG_MANUFACTURER_DATA].addr); - if (ret < 0) - return ret; - if (ret < sbs_data[REG_MANUFACTURER_DATA].min_value || ret > sbs_data[REG_MANUFACTURER_DATA].max_value) { val->intval = 0; @@ -950,16 +951,16 @@ static int sbs_suspend(struct device *dev) { struct i2c_client *client = to_i2c_client(dev); struct sbs_info *chip = i2c_get_clientdata(client); - s32 ret; if (chip->poll_time > 0) cancel_delayed_work_sync(&chip->work); - /* write to manufacturer access with sleep command */ - ret = sbs_write_word_data(client, sbs_data[REG_MANUFACTURER_DATA].addr, + /* + * Write to manufacturer access with sleep command. + * Support is manufacturer dependend, so ignore errors. + */ + sbs_write_word_data(client, sbs_data[REG_MANUFACTURER_DATA].addr, MANUFACTURER_ACCESS_SLEEP); - if (chip->is_present && ret < 0) - return ret; return 0; }