Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp427071imc; Sun, 10 Mar 2019 09:48:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqxsGA2MGDklMQRtGEzjg/esjglGNwsgXhcThUAh5MBbEihKaaBMd6LdmLo+g9aIqyR/SXWI X-Received: by 2002:a62:ee03:: with SMTP id e3mr29533967pfi.241.1552236512363; Sun, 10 Mar 2019 09:48:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552236512; cv=none; d=google.com; s=arc-20160816; b=bCV6Kv5Y2lN++Ng5JBER4zBi4We7tXUan648Zj+AAtbPbs0/M0TgfSS+qWS9Lk+Lf8 7TCX3XNPpxjuPppRtwsf2g/kKLsphmCiHAF6a/Zjjxek3SQepgRiewUiESn3uo/AL+Wd L1RC4aXzJn6wtfxqIlog4OOBTNvg7Vvg6YWpV8Z538i0Jl4rZKS2HvuZeLJuCqshqYeX uHgejclLP+DII+MbeBQmPDRz7qVqV6l46Q980AlKGyNZCoB+aER6CblDFM1SDmD3XIW9 LKeEWcehikfQwXHlFZwmRJvYHcpoyf6KH4u/k8/0J6yx6znQpCROuamYnWvFwWORYwB8 gFcA== 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=OPqXVnn8HHGPU1yEYUTRivcv598hNQpmIkDGoro1uoo=; b=Cw+y8pg0L/Sfy0zeIhynkgFQqCRfVNMEL5QjSE/zSHlVBokRApT8aLJ/AeUpAHnuzU z6Bz2TjLq4JsAIZjh9KzBYEAzVt11t2A66+pcc0qVtFz+duQwHiZmNedtd1LvgOJvXG/ O4f98JZehWagRtXEHNsZQG0Osd89BPpIJsZSu7y85ttri6StjqLuowZdwp9Q+oinAIY3 t2ZRMlXC4MvBCViy5X0myghS16MC7b2rVwACI9w9dg290VwhnCj9EZKYAcEbdEemUjyE oHJ48tPdJlrzl9jTuzJeynsAQ2IdBFQBblmtK/19iSp+bmMcgUejWJr8JTorrcmKRGvn EHLw== 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 e12si3061959pgd.381.2019.03.10.09.47.52; Sun, 10 Mar 2019 09:48:32 -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 S1726735AbfCJQY6 (ORCPT + 99 others); Sun, 10 Mar 2019 12:24:58 -0400 Received: from shell.v3.sk ([90.176.6.54]:45130 "EHLO shell.v3.sk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726698AbfCJQYz (ORCPT ); Sun, 10 Mar 2019 12:24:55 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id DE863102CAC; Sun, 10 Mar 2019 17:24:51 +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 oeSKxz6QfxTN; Sun, 10 Mar 2019 17:24:42 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id 932AF102CB4; Sun, 10 Mar 2019 17:24:34 +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 e2bpPG4pwsIh; Sun, 10 Mar 2019 17:24:32 +0100 (CET) Received: from nedofet.lan (ip-89-102-31-34.net.upcbroadband.cz [89.102.31.34]) by zimbra.v3.sk (Postfix) with ESMTPSA id 6BD6D102CB5; Sun, 10 Mar 2019 17:24:31 +0100 (CET) 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 Subject: [PATCH 09/10] power: supply: olpc_battery: Add OLPC XO 1.75 support Date: Sun, 10 Mar 2019 17:24:18 +0100 Message-Id: <20190310162419.11861-10-lkundrak@v3.sk> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190310162419.11861-1-lkundrak@v3.sk> References: <20190310162419.11861-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 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.20.1