Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp671562imu; Fri, 16 Nov 2018 08:26:31 -0800 (PST) X-Google-Smtp-Source: AJdET5fyNQpRKG/4DxOeSiQ6SW6BpgjJIc8sen4epy3uiVwZS80gi9q7FJPo5d+m8+seYjVdWcra X-Received: by 2002:a17:902:3103:: with SMTP id w3-v6mr11736396plb.18.1542385591392; Fri, 16 Nov 2018 08:26:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542385591; cv=none; d=google.com; s=arc-20160816; b=FupFsb09q2zZ2Y7aFBDutIzAOWoq8UlNAM7+ov/D6TueoHJAtLbj/dTZykzEz17zVJ 66Zyh4SF+FwDK5H9UZmajZ/nHY+HGr0s66gloBMS8KvtyP1kzQr9x7/H7q++7L2HLJ2C F1tm3NNPVlEB7s8EQaHpse1xdIa93AZsY6niJvvnJXXbh/xpBgFWTRa/y6LjeMXP68I4 hYg5cZst9oQtl40alJcfAEIfMn8wVHUjuczsYsu6OYsKT4gqfrbGuk8BvY1g2xIUlpd1 tSQDxt0f8qQ+2UZ0pD8VPrvZB5O28tuU7NA5VQLuMIvrgHF5juBvGc/4qozKdHcJFhS9 vLPw== 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=eqbGYaefo8AnDHlVsp712QVD5OhLi5Qsf/gi7rTE8bk=; b=a8+Xkhk+2UxjS7vLo1i5NhoZ+u+LZUAex3FPXD2sLqkuz8hLcr578nwZvvOH4Gkzmt WVCdIq3PePG4G32Bb81NdSKwZ9BZh74QbD+TiejicU1ZuVQq5dMuuQcUBNiDVrg0yhgm sEP8C3RvrVROoGP1IyBcEnA0ZcWVgYiMjgh/wCpNFsE/o/qii0sUSI690FoBtJr76Pz4 Tq1rL0rLMPSQtmDXwvhut+xZxf9+FMSpuXt8J4STrxlDriYvOCi3g6dD1PGwXox7Y5r4 7csrRMClwaD8uam10p0jnrmVOt1/GYBSIRQoPt37PAag3NpfE46acCAX2PUQOhtLvqbY thLw== 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 h9si29631085pgb.319.2018.11.16.08.26.16; Fri, 16 Nov 2018 08:26:31 -0800 (PST) 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 S2390456AbeKQCi0 (ORCPT + 99 others); Fri, 16 Nov 2018 21:38:26 -0500 Received: from shell.v3.sk ([90.176.6.54]:57160 "EHLO shell.v3.sk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390306AbeKQCiZ (ORCPT ); Fri, 16 Nov 2018 21:38:25 -0500 Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id 876C052FB0; Fri, 16 Nov 2018 17:25:19 +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 PwbUUI4kReoR; Fri, 16 Nov 2018 17:24:54 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id 0B81552A9A; Fri, 16 Nov 2018 17:24:30 +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 33Ms218LSzzE; Fri, 16 Nov 2018 17:24:27 +0100 (CET) Received: from belphegor.brq.redhat.com (nat-pool-brq-t.redhat.com [213.175.37.10]) by zimbra.v3.sk (Postfix) with ESMTPSA id 4485F530C9; Fri, 16 Nov 2018 17:24:20 +0100 (CET) From: Lubomir Rintel To: Mark Brown , Geert Uytterhoeven , Darren Hart , Andy Shevchenko Cc: Greg Kroah-Hartman , James Cameron , Sebastian Reichel , Rob Herring , Mark Rutland , Eric Miao , Haojian Zhuang , Daniel Mack , Robert Jarzmik , linux-spi@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, platform-driver-x86@vger.kernel.org, devel@driverdev.osuosl.org, linux-pm@vger.kernel.org, Lubomir Rintel Subject: [PATCH v2 16/17] power: supply: olpc_battery: Avoid using platform_info Date: Fri, 16 Nov 2018 17:24:02 +0100 Message-Id: <20181116162403.49854-17-lkundrak@v3.sk> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181116162403.49854-1-lkundrak@v3.sk> References: <20181116162403.49854-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 This wouldn't work on the DT-based ARM platform. Let's read the EC versio= n directly from the EC driver instead. This makes the driver no longer x86 specific. Signed-off-by: Lubomir Rintel Acked-by: Pavel Machek --- Changes since v1: - Use uint8_t instead of unsigned char [1] for ecver drivers/power/supply/Kconfig | 2 +- drivers/power/supply/olpc_battery.c | 35 +++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig index f27cf0709500..dd7ae1431098 100644 --- a/drivers/power/supply/Kconfig +++ b/drivers/power/supply/Kconfig @@ -151,7 +151,7 @@ config BATTERY_PMU =20 config BATTERY_OLPC tristate "One Laptop Per Child battery" - depends on X86_32 && OLPC + depends on OLPC help Say Y to enable support for the battery on the OLPC laptop. =20 diff --git a/drivers/power/supply/olpc_battery.c b/drivers/power/supply/o= lpc_battery.c index 4433eb10a23d..ec5dfb8fcb8a 100644 --- a/drivers/power/supply/olpc_battery.c +++ b/drivers/power/supply/olpc_battery.c @@ -20,8 +20,6 @@ #include #include #include -#include - =20 #define EC_BAT_VOLTAGE 0x10 /* uint16_t, *9.76/32, mV */ #define EC_BAT_CURRENT 0x11 /* int16_t, *15.625/120, mA */ @@ -57,6 +55,7 @@ struct olpc_battery_data { struct power_supply *olpc_ac; struct power_supply *olpc_bat; char bat_serial[17]; + int new_proto; }; =20 /********************************************************************* @@ -100,7 +99,7 @@ static const struct power_supply_desc olpc_ac_desc =3D= { static int olpc_bat_get_status(struct olpc_battery_data *data, union power_supply_propval *val, uint8_t ec_byte) { - if (olpc_platform_info.ecver > 0x44) { + if (data->new_proto) { if (ec_byte & (BAT_STAT_CHARGING | BAT_STAT_TRICKLE)) val->intval =3D POWER_SUPPLY_STATUS_CHARGING; else if (ec_byte & BAT_STAT_DISCHARGING) @@ -608,14 +607,32 @@ static int olpc_battery_probe(struct platform_devic= e *pdev) struct power_supply_config psy_cfg =3D {}; struct olpc_battery_data *data; uint8_t status; + uint8_t ecver; + int ret; + + data =3D devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + platform_set_drvdata(pdev, data); + + /* See if the EC is already there and get the EC revision */ + ret =3D olpc_ec_cmd(EC_FIRMWARE_REV, NULL, 0, &ecver, 1); + if (ret) { + if (ret =3D=3D -ENODEV) + return -EPROBE_DEFER; + return ret; + } =20 - /* - * We've seen a number of EC protocol changes; this driver requires - * the latest EC protocol, supported by 0x44 and above. - */ - if (olpc_platform_info.ecver < 0x44) { + if (ecver > 0x44) { + /* XO 1 or 1.5 with a new EC firmware. */ + data->new_proto =3D 1; + } else if (ecver < 0x44) { + /* + * We've seen a number of EC protocol changes; this driver + * requires the latest EC protocol, supported by 0x44 and above. + */ printk(KERN_NOTICE "OLPC EC version 0x%02x too old for " - "battery driver.\n", olpc_platform_info.ecver); + "battery driver.\n", ecver); return -ENXIO; } =20 --=20 2.19.1