From patchwork Fri Nov 16 16:24:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lubomir Rintel X-Patchwork-Id: 10686647 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 47E8C14D6 for ; Fri, 16 Nov 2018 16:29:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 32F532CA52 for ; Fri, 16 Nov 2018 16:29:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 238932CA64; Fri, 16 Nov 2018 16:29:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AC7F42CA52 for ; Fri, 16 Nov 2018 16:29:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=U5jGMGo8yoLVhgu/otry59gjM+Wf7gHMOuKf1bObIH0=; b=emw7Mq9IdDbQE+ cYCPZtnoYVeUThF+/kc3J76bU85fqooI0POKp8Suif3hza6iVZ14k1MF9zeJ+OId02pv66cD8hFHG asLgQ4IEi5F/BFt+cg5xRBwXnLBPeGbD+sWXyx/PBmZ7iA4KKuvLhB2yQbaf0crEiEizIv+Sr+0KL ccvFguRw61faknHlqK+rZEsKCu1IDVHxrKLcMnXN4wuvlbjaqnGXYaJHQ3gQJpyO/JdW4VImL/04d YFvA4ZAHUZ9A3IsauoDuAhlrMjtlspJDCdbi+kjWmldesdU4HPewdEdO0w0TUl7Gmh0t20Xc/enON +NR02aF/LTgY0TbH6PZg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNgzS-0000Ws-3b; Fri, 16 Nov 2018 16:29:06 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNgvy-0005ns-To for linux-arm-kernel@bombadil.infradead.org; Fri, 16 Nov 2018 16:25:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=eqbGYaefo8AnDHlVsp712QVD5OhLi5Qsf/gi7rTE8bk=; b=b/GURIDmEzzj2E8nGj2BFbKoH0 AGt1F4GOz3SsNUXYzf0wjI5/GVaBf4fTTZ506OPVRTHXdiXWKrywcOnIbCMq9XUX4bwGhJPr9bQya adLt9jEtGsG8CXHFEUf2GvzFZh53Kz1xjYtv5ckvyQQWNuchfjpnNWHXNGwOKQCQ1XXGRMPiM9AGW X0PfKUA5AYpZmHNn90z8ito/shg9o1wYCT0DJV+RfRcP2tZweYWpNEq3MWX8Mov/O3pip1Sny05wn Op6F+R+4Kj90mSnU7nkaOO9bqIpTWgXn7pJGT2i4lkXpmh88wOaIW/xMXP4m4UPSJeZxYxHhY2Gb2 5dMtwEjA==; Received: from shell.v3.sk ([90.176.6.54]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNgvr-0001qf-MO for linux-arm-kernel@lists.infradead.org; Fri, 16 Nov 2018 16:25:29 +0000 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181116_162524_044324_3D55940D X-CRM114-Status: GOOD ( 23.18 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, devel@driverdev.osuosl.org, Eric Miao , James Cameron , linux-pm@vger.kernel.org, Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Sebastian Reichel , Haojian Zhuang , linux-spi@vger.kernel.org, Lubomir Rintel , Rob Herring , linux-arm-kernel@lists.infradead.org, platform-driver-x86@vger.kernel.org, Robert Jarzmik , Daniel Mack Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This wouldn't work on the DT-based ARM platform. Let's read the EC version directly from the EC driver instead. This makes the driver no longer x86 specific. Signed-off-by: Lubomir Rintel Acked-by: Pavel Machek Reviewed-by: Sebastian Reichel --- 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 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. diff --git a/drivers/power/supply/olpc_battery.c b/drivers/power/supply/olpc_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 - #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; }; /********************************************************************* @@ -100,7 +99,7 @@ static const struct power_supply_desc olpc_ac_desc = { 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 = POWER_SUPPLY_STATUS_CHARGING; else if (ec_byte & BAT_STAT_DISCHARGING) @@ -608,14 +607,32 @@ static int olpc_battery_probe(struct platform_device *pdev) struct power_supply_config psy_cfg = {}; struct olpc_battery_data *data; uint8_t status; + uint8_t ecver; + int ret; + + data = 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 = olpc_ec_cmd(EC_FIRMWARE_REV, NULL, 0, &ecver, 1); + if (ret) { + if (ret == -ENODEV) + return -EPROBE_DEFER; + return ret; + } - /* - * 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 = 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; }