From: Lubomir Rintel <lkundrak@v3.sk>
To: Sebastian Reichel <sre@kernel.org>
Cc: Rob Herring <robh+dt@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
x86@kernel.org, linux-pm@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
Lubomir Rintel <lkundrak@v3.sk>, Pavel Machek <pavel@ucw.cz>
Subject: [PATCH v5 7/7] power: supply: olpc_battery: Add OLPC XO 1.75 support
Date: Thu, 10 Jan 2019 18:40:05 +0100 [thread overview]
Message-ID: <20190110174005.1202564-8-lkundrak@v3.sk> (raw)
In-Reply-To: <20190110174005.1202564-1-lkundrak@v3.sk>
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 <lkundrak@v3.sk>
Acked-by: Pavel Machek <pavel@ucw.cz>
---
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/olpc_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;
};
/*********************************************************************
@@ -322,6 +323,14 @@ static int olpc_bat_get_voltage_max_design(union power_supply_propval *val)
return ret;
}
+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;
- val->intval = (s16)be16_to_cpu(ec_word) * 9760L / 32;
+ val->intval = 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;
- val->intval = (s16)be16_to_cpu(ec_word) * 15625L / 120;
+ val->intval = ecword_to_cpu(data, ec_word) * 15625L / 120;
break;
case POWER_SUPPLY_PROP_CAPACITY:
ret = olpc_ec_cmd(EC_BAT_SOC, NULL, 0, &ec_byte, 1);
@@ -433,21 +442,21 @@ static int olpc_bat_get_property(struct power_supply *psy,
if (ret)
return ret;
- val->intval = (s16)be16_to_cpu(ec_word) * 10 / 256;
+ val->intval = ecword_to_cpu(data, ec_word) * 10 / 256;
break;
case POWER_SUPPLY_PROP_TEMP_AMBIENT:
ret = olpc_ec_cmd(EC_AMB_TEMP, NULL, 0, (void *)&ec_word, 2);
if (ret)
return ret;
- val->intval = (int)be16_to_cpu(ec_word) * 10 / 256;
+ val->intval = (int)ecword_to_cpu(data, ec_word) * 10 / 256;
break;
case POWER_SUPPLY_PROP_CHARGE_COUNTER:
ret = olpc_ec_cmd(EC_BAT_ACR, NULL, 0, (void *)&ec_word, 2);
if (ret)
return ret;
- val->intval = (s16)be16_to_cpu(ec_word) * 6250 / 15;
+ val->intval = ecword_to_cpu(data, ec_word) * 6250 / 15;
break;
case POWER_SUPPLY_PROP_SERIAL_NUMBER:
ret = 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;
- if (ecver > 0x44) {
+ if (of_find_compatible_node(NULL, NULL, "olpc,xo1.75-ec")) {
+ /* XO 1.75 */
+ data->new_proto = 1;
+ data->little_endian = 1;
+ } else if (ecver > 0x44) {
/* XO 1 or 1.5 with a new EC firmware. */
data->new_proto = 1;
} else if (ecver < 0x44) {
--
2.20.1
next prev parent reply other threads:[~2019-01-10 17:40 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-10 17:39 [PATCH v5 1/7] Add support for XO 1.75 to OLPC battery driver Lubomir Rintel
2019-01-10 17:39 ` [PATCH v5 1/7] dt-bindings: olpc_battery: Add XO-1.5 battery Lubomir Rintel
2019-01-10 17:40 ` [PATCH v5 2/7] x86, olpc: Use a correct version when making up a battery node Lubomir Rintel
2019-01-23 20:56 ` Sebastian Reichel
2019-01-31 12:26 ` Lubomir Rintel
2019-01-31 12:59 ` Borislav Petkov
2019-02-11 11:37 ` Lubomir Rintel
2019-02-19 23:15 ` Sebastian Reichel
2019-03-07 5:01 ` Darren Hart
2019-01-10 17:40 ` [PATCH v5 3/7] power: supply: olpc_battery: Use DT to get battery version Lubomir Rintel
2019-01-23 20:38 ` Sebastian Reichel
2019-01-10 17:40 ` [PATCH v5 4/7] power: supply: olpc_battery: Move priv data to a struct Lubomir Rintel
2019-01-23 20:54 ` Sebastian Reichel
2019-01-10 17:40 ` [PATCH v5 5/7] power: supply: olpc_battery: Use devm_power_supply_register() Lubomir Rintel
2019-01-10 17:40 ` [PATCH v5 6/7] power: supply: olpc_battery: Avoid using platform_info Lubomir Rintel
2019-01-23 20:47 ` Sebastian Reichel
2019-01-10 17:40 ` Lubomir Rintel [this message]
2019-01-23 20:49 ` [PATCH v5 7/7] power: supply: olpc_battery: Add OLPC XO 1.75 support Sebastian Reichel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190110174005.1202564-8-lkundrak@v3.sk \
--to=lkundrak@v3.sk \
--cc=devicetree@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=pavel@ucw.cz \
--cc=robh+dt@kernel.org \
--cc=sre@kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox