Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2190476imu; Thu, 10 Jan 2019 09:44:11 -0800 (PST) X-Google-Smtp-Source: ALg8bN47FQO7kpXkESwH5y6zc6L2rarki4/8mDzNEBlDQSQcioH01szl7NzfAOhuYlFgc4wQ7jPY X-Received: by 2002:a62:6503:: with SMTP id z3mr10799784pfb.169.1547142251853; Thu, 10 Jan 2019 09:44:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547142251; cv=none; d=google.com; s=arc-20160816; b=WUOh75ndewKZRzC9IK8tuLC/l0DVDPP35b0rRvSrFc6M+N0Rnp6aFNYRZV7ca6uepj elxrOhVIdcQQ3ZDXVQZaozUs/STwRwexyJWoPd4yPOrPeopIqx+jZXYWnUklblMmR96e aFNnaHURvOEMnJMNreQbJGHEnnDLvOflasZL1WXUBMplHmhuen76CcX3EZnL8gC/jQuC hEMVwrGeMRCakzFzUolR6QFzPVgyg9Q70SKtYGs5T6aN4ggrmVZfWnP3nWFhFBmCmp9G 8wlpNW/N0xjRs/fdzcx1WgIpgL2zwkIwdp1xpMOhXB2Ga8T5tR6FC49fnqJPmckY7xx6 gzqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=PhjahcWyq0yqO/a2CrWbLAHjIxgaWOmm19yGojWHhN4=; b=oFZVT8hxS0qvCxx29IyEth2+AjsRWtLhnaUxalLPJ7K4bQ7PmWuhrsTcS45Yj/XvfO YYEj+fUQJsGAaEdxf2y8mvq3ynnWAbLFM9A+3dJKhNNRIk0PcMkYPv7/+Q4oBvf9bUBD LOYto6NzWMQPFkkqAE3Dn/MEwv+SCdOB5N8Q4jFxToa0NOSExyMTUTzIllZX2CSThEev fT7y0nMhW0mt5dUc1YzZ4kWKfj+LsR6FfmdAxctpD4w1Kp0NO1Xw6hmCnp2pO9wTmuOH Bv+AjRaiArmgstbVx4vNu6PB8dcC7B8X+FTuY5UQEA47KcRnKF6s4ibkDZlT9FUMOAWj C/Ng== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r77si22312047pfa.186.2019.01.10.09.43.56; Thu, 10 Jan 2019 09:44:11 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730766AbfAJRmc (ORCPT + 99 others); Thu, 10 Jan 2019 12:42:32 -0500 Received: from shell.v3.sk ([90.176.6.54]:58401 "EHLO shell.v3.sk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730730AbfAJRm3 (ORCPT ); Thu, 10 Jan 2019 12:42:29 -0500 Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id 2EDD91002E6; Thu, 10 Jan 2019 18:42:26 +0100 (CET) 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 IsD_WR98FtqE; Thu, 10 Jan 2019 18:42:14 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id D96091002F0; Thu, 10 Jan 2019 18:42:07 +0100 (CET) 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 pjagQpml1qh3; Thu, 10 Jan 2019 18:42:04 +0100 (CET) Received: from belphegor.brq.redhat.com (nat-pool-brq-t.redhat.com [213.175.37.10]) by zimbra.v3.sk (Postfix) with ESMTPSA id 114A81002EF; Thu, 10 Jan 2019 18:42:04 +0100 (CET) From: Lubomir Rintel To: Sebastian Reichel Cc: Rob Herring , Mark Rutland , x86@kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Lubomir Rintel , Pavel Machek Subject: [PATCH v5 7/7] power: supply: olpc_battery: Add OLPC XO 1.75 support Date: Thu, 10 Jan 2019 18:40:05 +0100 Message-Id: <20190110174005.1202564-8-lkundrak@v3.sk> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190110174005.1202564-1-lkundrak@v3.sk> References: <20190110174005.1202564-1-lkundrak@v3.sk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- Changes since v2: - Fix the version conditional Changes since v1: - s/s16 ecword_to_cpu/u16 ecword_to_cpu/ - s/u16 ec_byte/u16 ec_word/ drivers/power/supply/olpc_battery.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/drivers/power/supply/olpc_battery.c b/drivers/power/supply/o= lpc_battery.c index a6c89d002d5d..52de90049980 100644 --- a/drivers/power/supply/olpc_battery.c +++ b/drivers/power/supply/olpc_battery.c @@ -57,6 +57,7 @@ struct olpc_battery_data { struct power_supply *olpc_bat; char bat_serial[17]; int new_proto; + int little_endian; }; =20 /********************************************************************* @@ -322,6 +323,14 @@ static int olpc_bat_get_voltage_max_design(union pow= er_supply_propval *val) return ret; } =20 +static u16 ecword_to_cpu(struct olpc_battery_data *data, u16 ec_word) +{ + if (data->little_endian) + return le16_to_cpu(ec_word); + else + return be16_to_cpu(ec_word); +} + /********************************************************************* * Battery properties *********************************************************************/ @@ -394,7 +403,7 @@ static int olpc_bat_get_property(struct power_supply = *psy, if (ret) return ret; =20 - val->intval =3D (s16)be16_to_cpu(ec_word) * 9760L / 32; + val->intval =3D ecword_to_cpu(data, ec_word) * 9760L / 32; break; case POWER_SUPPLY_PROP_CURRENT_AVG: case POWER_SUPPLY_PROP_CURRENT_NOW: @@ -402,7 +411,7 @@ static int olpc_bat_get_property(struct power_supply = *psy, if (ret) return ret; =20 - val->intval =3D (s16)be16_to_cpu(ec_word) * 15625L / 120; + val->intval =3D ecword_to_cpu(data, ec_word) * 15625L / 120; break; case POWER_SUPPLY_PROP_CAPACITY: ret =3D olpc_ec_cmd(EC_BAT_SOC, NULL, 0, &ec_byte, 1); @@ -433,21 +442,21 @@ static int olpc_bat_get_property(struct power_suppl= y *psy, if (ret) return ret; =20 - val->intval =3D (s16)be16_to_cpu(ec_word) * 10 / 256; + val->intval =3D ecword_to_cpu(data, ec_word) * 10 / 256; break; case POWER_SUPPLY_PROP_TEMP_AMBIENT: ret =3D olpc_ec_cmd(EC_AMB_TEMP, NULL, 0, (void *)&ec_word, 2); if (ret) return ret; =20 - val->intval =3D (int)be16_to_cpu(ec_word) * 10 / 256; + val->intval =3D (int)ecword_to_cpu(data, ec_word) * 10 / 256; break; case POWER_SUPPLY_PROP_CHARGE_COUNTER: ret =3D olpc_ec_cmd(EC_BAT_ACR, NULL, 0, (void *)&ec_word, 2); if (ret) return ret; =20 - val->intval =3D (s16)be16_to_cpu(ec_word) * 6250 / 15; + val->intval =3D ecword_to_cpu(data, ec_word) * 6250 / 15; break; case POWER_SUPPLY_PROP_SERIAL_NUMBER: ret =3D olpc_ec_cmd(EC_BAT_SERIAL, NULL, 0, (void *)&ser_buf, 8); @@ -621,7 +630,11 @@ static int olpc_battery_probe(struct platform_device= *pdev) if (ret) return ret; =20 - if (ecver > 0x44) { + if (of_find_compatible_node(NULL, NULL, "olpc,xo1.75-ec")) { + /* XO 1.75 */ + data->new_proto =3D 1; + data->little_endian =3D 1; + } else if (ecver > 0x44) { /* XO 1 or 1.5 with a new EC firmware. */ data->new_proto =3D 1; } else if (ecver < 0x44) { --=20 2.20.1