Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp676009yba; Thu, 18 Apr 2019 07:49:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqz40/a/5kRiR06z2IHHLIY6uClQ0u7YzoyS/2cQuiBYTA+CnMHmrFbrgPAhuB+06Q/3gHXD X-Received: by 2002:a62:121c:: with SMTP id a28mr95719842pfj.58.1555598945265; Thu, 18 Apr 2019 07:49:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555598945; cv=none; d=google.com; s=arc-20160816; b=Odz76X3g3AZesU+L6WrKc4QdmNFDgFcvHrQwgvEJsXhG/U0hV4xbqxKWaw3W7I35u2 jy7KLqky4sDFuSk3lQCP+qz4cfA8qww6i15PY/K8C0QEkj/ef0MRxK3WYfXcSNw16XjY 2Q4NqvOezQytFoBpwX4kVmdisOQ1txj62UUv3w0hTdwZqzffqjMDrpbd1kDAJEKm7lJR MG2ye3sD+igwcW7sLiGuXqaMR6xKOfR3wxjRLjqU06nWdXbEwOVRlNR8AxRcfFmsrL6n qf52hzeap+dB88nKsMK6LS8coaW1UT7sROg9TGRjefbQShxKgpJDV/6XwgSaFFfFEdSz QhKQ== 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=GqzQRtmQOQneJ3QKce6udxhBdumT8s/lYw2YDADh0B4=; b=sKvi19A7Eb4ySivIwDYH+Kev7aHKAlE66o/NYdFdjVqc4BiUTs0t+awkOU5Zgq5NCZ Cr0+rFeNxVAmKPSw4oQAsNjX/ZqbgLjH8D6sLmeoINd4tGRS1DGsTqt82x2pn8uQ0047 Tw1zhftt2ROLFO1BVPCovdHUQVmHwo94WGSt52ikd2l5VPq00odEETxsWU78OGE90MZc fnHeXukD2DHnpc1/TJKm9CV3Z20G6s2qGYWs/LLqOsEJoyU+VBomeO/F5DQWCCs5VVhi byQIXaJQzIbtHY7GY5v4ViOs61P+E6ROgyOyGRM/CroUMnxRCs+ZuxQRy890iL5VtPPF VXbA== 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 s20si2066006pgm.137.2019.04.18.07.48.50; Thu, 18 Apr 2019 07:49:05 -0700 (PDT) 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 S2389514AbfDROrn (ORCPT + 99 others); Thu, 18 Apr 2019 10:47:43 -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