linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sebastian Reichel <sre@kernel.org>
To: Lubomir Rintel <lkundrak@v3.sk>
Cc: Darren Hart <dvhart@infradead.org>,
	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,
	Pavel Machek <pavel@ucw.cz>
Subject: Re: [PATCH 09/10] power: supply: olpc_battery: Add OLPC XO 1.75 support
Date: Fri, 5 Apr 2019 15:50:25 +0200	[thread overview]
Message-ID: <20190405135025.v4sn33mkgdrsjvtm@earth.universe> (raw)
In-Reply-To: <20190310162419.11861-10-lkundrak@v3.sk>

[-- Attachment #1: Type: text/plain, Size: 3809 bytes --]

Hi,

On Sun, Mar 10, 2019 at 05:24:18PM +0100, Lubomir Rintel wrote:
> 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>
> 
> ---

Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.com>

-- Sebastian

> 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/olpc_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;
>  };
>  
>  /*********************************************************************
> @@ -323,6 +324,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
>   *********************************************************************/
> @@ -395,7 +404,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:
> @@ -403,7 +412,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);
> @@ -434,21 +443,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);
> @@ -622,7 +631,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 = true;
> +		data->little_endian = true;
> +	} else if (ecver > 0x44) {
>  		/* XO 1 or 1.5 with a new EC firmware. */
>  		data->new_proto = true;
>  	} else if (ecver < 0x44) {
> -- 
> 2.20.1
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2019-04-05 13:50 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-10 16:24 [PATCH 00/10] Add support for XO 1.75 to OLPC battery driver Lubomir Rintel
2019-03-10 16:24 ` [PATCH 01/10] dt-bindings: olpc_battery: Add XO-1.5 battery Lubomir Rintel
2019-03-10 16:24 ` [PATCH 02/10] x86, olpc: Don't split string literals when fixing up the DT Lubomir Rintel
2019-03-22 23:18   ` Thomas Gleixner
2019-03-10 16:24 ` [PATCH 03/10] x86, olpc: Trivial code move in DT fixup Lubomir Rintel
2019-03-22 23:20   ` Thomas Gleixner
2019-03-10 16:24 ` [PATCH 04/10] x86, olpc: Use a correct version when making up a battery node Lubomir Rintel
2019-03-22 23:25   ` Thomas Gleixner
2019-04-05 13:59     ` Sebastian Reichel
2019-03-10 16:24 ` [PATCH 05/10] power: supply: olpc_battery: Use DT to get battery version Lubomir Rintel
2019-03-10 16:24 ` [PATCH 06/10] power: supply: olpc_battery: Move priv data to a struct Lubomir Rintel
2019-04-05 13:45   ` Sebastian Reichel
2019-03-10 16:24 ` [PATCH 07/10] power: supply: olpc_battery: Use devm_power_supply_register() Lubomir Rintel
2019-03-10 16:24 ` [PATCH 08/10] power: supply: olpc_battery: Avoid using platform_info Lubomir Rintel
2019-03-10 16:24 ` [PATCH 09/10] power: supply: olpc_battery: Add OLPC XO 1.75 support Lubomir Rintel
2019-04-05 13:50   ` Sebastian Reichel [this message]
2019-03-10 16:24 ` [PATCH 10/10] power: supply: olpc_battery: Have the framework register sysfs files for us Lubomir Rintel
2019-04-05 13:49   ` 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=20190405135025.v4sn33mkgdrsjvtm@earth.universe \
    --to=sre@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dvhart@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=lkundrak@v3.sk \
    --cc=mark.rutland@arm.com \
    --cc=pavel@ucw.cz \
    --cc=robh+dt@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;
as well as URLs for NNTP newsgroup(s).