Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp671773imu; Fri, 16 Nov 2018 08:26:42 -0800 (PST) X-Google-Smtp-Source: AJdET5dU830PeEyRm4CrNsoUDrRRhl71P19ESfKewZ7elQPV1LuV2R4EQs4LxFAMjVkLdUqDnWNY X-Received: by 2002:a63:2222:: with SMTP id i34mr9710920pgi.83.1542385602796; Fri, 16 Nov 2018 08:26:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542385602; cv=none; d=google.com; s=arc-20160816; b=RYuQjq5yP/qcaZF1ufaMaebnmL5RGtfWRHkP3ZlH/qG9xMAQBb6SrHTS50gz1aMam7 6wEk2eMdGEx5jDhfNSWXXfgWdUMM8FFC6JTHE3IBshE6oE9wThQhE273eVR6Nij6VMSf g+fadL6CKNQAlyN5HeJh5mmKWs+ulXaMZIB8hkIouK3LF9DodI4u8WPbXIAMZMpaV9OX wq+jwYTKIltC+dtx/TeQIj+eix6e1U2KFrJv6hQggnx1aMKx+MxEcjLmW1rfewjnbuHT TIwzsa9b7w6i+snKoZgS6FgCyT1bF9W2CbbgMndEHf/sX9DQ3T8jZ5F/eRSLz90sydrY W9zA== 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=ibWlj6kEsLgn0DDcqVvyeCoVE9y7mF3H8lzQ72gvS+Y=; b=0O8vV89flw3IZypuFQNV2cyOSKVQiBmX+g1lBm3xIUr32xFp/xQrqh9DfApf6peldV CViFSpvlMGiU7K7eaaSRk7msz0B5DT6KVDeqPEknbl7Fod1lnrm5gB8Hnt45r/Bk4Xd5 y4jDAuzinmBIGd2ssM+9xM1J6aqgvheKzXWNGpzDjQnVEwNjTVQ8q80HiQgMkjr6xuzp QdDjmo1sXWVXxaQvEzvE+DxnYDlfKRiXNfuBRmMFPIv4JXNgmaWfnEr7zIgC0pEZPip1 CAdzcmrVI98FMOu45l2EmcZAlINA9s6z85fLUED+rSPSCMDekdgdBrEcOxwIeRp5N6C4 851w== 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 k15si29692174pgi.99.2018.11.16.08.26.28; Fri, 16 Nov 2018 08:26:42 -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 S2390466AbeKQCih (ORCPT + 99 others); Fri, 16 Nov 2018 21:38:37 -0500 Received: from shell.v3.sk ([90.176.6.54]:57245 "EHLO shell.v3.sk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390402AbeKQCi0 (ORCPT ); Fri, 16 Nov 2018 21:38:26 -0500 Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id 81BC552C13; Fri, 16 Nov 2018 17:25:21 +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 wCnVJy5VdY0x; Fri, 16 Nov 2018 17:25:02 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id 2D9A952AE0; Fri, 16 Nov 2018 17:24:30 +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 SKWLQ4zRNLNC; Fri, 16 Nov 2018 17:24:27 +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 A0DE8530E2; Fri, 16 Nov 2018 17:24:20 +0100 (CET) From: Lubomir Rintel To: Mark Brown , Geert Uytterhoeven , Darren Hart , Andy Shevchenko Cc: Greg Kroah-Hartman , James Cameron , Sebastian Reichel , Rob Herring , Mark Rutland , Eric Miao , Haojian Zhuang , Daniel Mack , Robert Jarzmik , linux-spi@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, platform-driver-x86@vger.kernel.org, devel@driverdev.osuosl.org, linux-pm@vger.kernel.org, Lubomir Rintel Subject: [PATCH v2 17/17] power: supply: olpc_battery: Add OLPC XO 1.75 support Date: Fri, 16 Nov 2018 17:24:03 +0100 Message-Id: <20181116162403.49854-18-lkundrak@v3.sk> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181116162403.49854-1-lkundrak@v3.sk> References: <20181116162403.49854-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 v1: - s/s16 ecword_to_cpu/u16 ecword_to_cpu/ - s/u16 ec_byte/u16 ec_word/ 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/o= lpc_battery.c index ec5dfb8fcb8a..898e8a6128bb 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; }; =20 /********************************************************************* @@ -321,6 +322,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 *********************************************************************/ @@ -393,7 +402,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: @@ -401,7 +410,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); @@ -432,21 +441,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); @@ -626,6 +635,10 @@ static int olpc_battery_probe(struct platform_device= *pdev) if (ecver > 0x44) { /* XO 1 or 1.5 with a new EC firmware. */ data->new_proto =3D 1; + } else 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) { /* * We've seen a number of EC protocol changes; this driver --=20 2.19.1