From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8EE0AC10F0E for ; Thu, 18 Apr 2019 14:47:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6566B2183E for ; Thu, 18 Apr 2019 14:47:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389526AbfDROro (ORCPT ); Thu, 18 Apr 2019 10:47:44 -0400 Received: from shell.v3.sk ([90.176.6.54]:48061 "EHLO shell.v3.sk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389480AbfDROri (ORCPT ); Thu, 18 Apr 2019 10:47:38 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id 4AFE41027A8; Thu, 18 Apr 2019 16:47:35 +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 d77oAr1bV4rf; Thu, 18 Apr 2019 16:47:19 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id C01611027AD; Thu, 18 Apr 2019 16:47:08 +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 lK6YreQyY5ju; Thu, 18 Apr 2019 16:47:04 +0200 (CEST) Received: from belphegor.brq.redhat.com (nat-pool-brq-t.redhat.com [213.175.37.10]) by zimbra.v3.sk (Postfix) with ESMTPSA id 5213C1027BA; Thu, 18 Apr 2019 16:47:01 +0200 (CEST) From: Lubomir Rintel To: Sebastian Reichel Cc: Darren Hart , 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 , Sebastian Reichel Subject: [PATCH v7 09/10] power: supply: olpc_battery: Add OLPC XO 1.75 support Date: Thu, 18 Apr 2019 16:46:54 +0200 Message-Id: <20190418144655.18758-10-lkundrak@v3.sk> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190418144655.18758-1-lkundrak@v3.sk> References: <20190418144655.18758-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 Reviewed-by: Sebastian Reichel --- Changes since v6: - Collect review tag from Sebastian Reichel Changes since v5: - s/int little_endian/bool little_endian/ 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 8be44c717d85..0d67158c13d6 100644 --- a/drivers/power/supply/olpc_battery.c +++ b/drivers/power/supply/olpc_battery.c @@ -58,6 +58,7 @@ struct olpc_battery_data { struct power_supply *olpc_bat; char bat_serial[17]; bool new_proto; + bool little_endian; }; =20 /********************************************************************* @@ -323,6 +324,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 *********************************************************************/ @@ -395,7 +404,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: @@ -403,7 +412,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); @@ -434,21 +443,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); @@ -622,7 +631,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 true; + data->little_endian =3D true; + } else if (ecver > 0x44) { /* XO 1 or 1.5 with a new EC firmware. */ data->new_proto =3D true; } else if (ecver < 0x44) { --=20 2.21.0