From patchwork Wed Oct 10 17:23:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lubomir Rintel X-Patchwork-Id: 10635031 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D72BA17E3 for ; Wed, 10 Oct 2018 17:31:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB8AC2A75E for ; Wed, 10 Oct 2018 17:31:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ABD7A2A7BF; Wed, 10 Oct 2018 17:31:36 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1EF6E2A75E for ; Wed, 10 Oct 2018 17:31:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=wqKX1hI2y14XkqAG0vsOl+KRkIl+fB/e5j866h5SeIk=; b=AVXDjRHLttLgUu umobI5TBHZ0298ZHcho6/MjT0Cw+BoQ4Lf2ObI7cnvPUebio37r06orvipBN/4S1gFKymyLgw8mCH dpJZp+s9VdaqpPwYS8q2W4iQNw3F1KtmrLAmvyVijRubKKNUqNvtNa8x3R43LaFXqOHPlZoRa6uwJ /aDlfDE5NuqQL03lsKS13T8lUjLgW26/wo7/To+ghaYeop8RX6c9MHXg97lW1XgGAeeSO3b4ZL06h iyl7cS2T1TbgcCTN35HScntoMS8Scii2itqOu6HBf5cKj1DT3Lib8dzix6oeaGobCC2qS2FUgmGWo ble1/bWrdrZqul0UhDpg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gAIKP-0005X4-Co; Wed, 10 Oct 2018 17:31:21 +0000 Received: from shell.v3.sk ([90.176.6.54]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gAIDG-0008P6-40 for linux-arm-kernel@lists.infradead.org; Wed, 10 Oct 2018 17:24:28 +0000 Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id AF300AE23F; Wed, 10 Oct 2018 19:23:54 +0200 (CEST) Received: from shell.v3.sk ([127.0.0.1]) by localhost (zimbra.v3.sk [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id vbNj-pXjtM_Q; Wed, 10 Oct 2018 19:23:35 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id D4420BCFAD; Wed, 10 Oct 2018 19:23:18 +0200 (CEST) X-Virus-Scanned: amavisd-new at zimbra.v3.sk Received: from shell.v3.sk ([127.0.0.1]) by localhost (zimbra.v3.sk [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id UKlJIzD9Q5Vy; Wed, 10 Oct 2018 19:23:16 +0200 (CEST) Received: from belphegor.lan (ip-89-102-31-34.net.upcbroadband.cz [89.102.31.34]) by zimbra.v3.sk (Postfix) with ESMTPSA id 90E96BCFBE; Wed, 10 Oct 2018 19:23:10 +0200 (CEST) From: Lubomir Rintel To: Mark Brown , Geert Uytterhoeven , Darren Hart , Andy Shevchenko Subject: [PATCH 15/15] power: supply: olpc_battery: Add OLPC XO 1.75 support Date: Wed, 10 Oct 2018 19:23:00 +0200 Message-Id: <20181010172300.317643-16-lkundrak@v3.sk> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181010172300.317643-1-lkundrak@v3.sk> References: <20181010172300.317643-1-lkundrak@v3.sk> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181010_102358_532930_CDE89E46 X-CRM114-Status: GOOD ( 12.21 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, devel@driverdev.osuosl.org, Eric Miao , James Cameron , linux-pm@vger.kernel.org, Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Sebastian Reichel , Haojian Zhuang , linux-spi@vger.kernel.org, Lubomir Rintel , Rob Herring , linux-arm-kernel@lists.infradead.org, platform-driver-x86@vger.kernel.org, Robert Jarzmik , Daniel Mack Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The battery and the protocol are essentially the same as OLPC XO 1.5, but the responses from the EC are LSB first. Signed-off-by: Lubomir Rintel Acked-by: Pavel Machek --- drivers/power/supply/olpc_battery.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/drivers/power/supply/olpc_battery.c b/drivers/power/supply/olpc_battery.c index dde9863e5c4a..2adf33b9f641 100644 --- a/drivers/power/supply/olpc_battery.c +++ b/drivers/power/supply/olpc_battery.c @@ -56,6 +56,7 @@ struct olpc_battery_data { struct power_supply *olpc_bat; char bat_serial[17]; int new_proto; + int little_endian; }; /********************************************************************* @@ -321,6 +322,14 @@ static int olpc_bat_get_voltage_max_design(union power_supply_propval *val) return ret; } +static s16 ecword_to_cpu(struct olpc_battery_data *data, u16 ec_byte) +{ + if (data->little_endian) + return le16_to_cpu(ec_byte); + else + return be16_to_cpu(ec_byte); +} + /********************************************************************* * Battery properties *********************************************************************/ @@ -393,7 +402,7 @@ static int olpc_bat_get_property(struct power_supply *psy, if (ret) return ret; - val->intval = (s16)be16_to_cpu(ec_word) * 9760L / 32; + val->intval = ecword_to_cpu(data, ec_word) * 9760L / 32; break; case POWER_SUPPLY_PROP_CURRENT_AVG: case POWER_SUPPLY_PROP_CURRENT_NOW: @@ -401,7 +410,7 @@ static int olpc_bat_get_property(struct power_supply *psy, if (ret) return ret; - val->intval = (s16)be16_to_cpu(ec_word) * 15625L / 120; + val->intval = ecword_to_cpu(data, ec_word) * 15625L / 120; break; case POWER_SUPPLY_PROP_CAPACITY: ret = olpc_ec_cmd(EC_BAT_SOC, NULL, 0, &ec_byte, 1); @@ -432,21 +441,21 @@ static int olpc_bat_get_property(struct power_supply *psy, if (ret) return ret; - val->intval = (s16)be16_to_cpu(ec_word) * 10 / 256; + val->intval = ecword_to_cpu(data, ec_word) * 10 / 256; break; case POWER_SUPPLY_PROP_TEMP_AMBIENT: ret = olpc_ec_cmd(EC_AMB_TEMP, NULL, 0, (void *)&ec_word, 2); if (ret) return ret; - val->intval = (int)be16_to_cpu(ec_word) * 10 / 256; + val->intval = (int)ecword_to_cpu(data, ec_word) * 10 / 256; break; case POWER_SUPPLY_PROP_CHARGE_COUNTER: ret = olpc_ec_cmd(EC_BAT_ACR, NULL, 0, (void *)&ec_word, 2); if (ret) return ret; - val->intval = (s16)be16_to_cpu(ec_word) * 6250 / 15; + val->intval = ecword_to_cpu(data, ec_word) * 6250 / 15; break; case POWER_SUPPLY_PROP_SERIAL_NUMBER: ret = olpc_ec_cmd(EC_BAT_SERIAL, NULL, 0, (void *)&ser_buf, 8); @@ -626,6 +635,10 @@ static int olpc_battery_probe(struct platform_device *pdev) if (ecver[0] > 0x44) { /* XO 1 or 1.5 with a new EC firmware. */ data->new_proto = 1; + } else if (of_find_compatible_node(NULL, NULL, "olpc,xo1.75-ec")) { + /* XO 1.75 */ + data->new_proto = 1; + data->little_endian = 1; } else if (ecver[0] < 0x44) { /* * We've seen a number of EC protocol changes; this driver