From patchwork Mon Jul 5 22:32:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1500971 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=ClrCDPmO; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GJgVV6Gjhz9sWq for ; Tue, 6 Jul 2021 08:34:58 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7AAB582C28; Tue, 6 Jul 2021 00:33:56 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="ClrCDPmO"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7BA2E82C0D; Tue, 6 Jul 2021 00:33:30 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-oi1-x22a.google.com (mail-oi1-x22a.google.com [IPv6:2607:f8b0:4864:20::22a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id B3C8C82BFF for ; Tue, 6 Jul 2021 00:33:21 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-oi1-x22a.google.com with SMTP id s24so7287130oiw.2 for ; Mon, 05 Jul 2021 15:33:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VpHme89Z0rCPic1Nkuyy0owdmlkiCOT5gaBDWHl46G4=; b=ClrCDPmO77zut53rL0BG55cUmyXfq0J78ghE/N3bXqvNgcKqAbY8TicaQVoi1EiC7w wfozj41CukHnytGRc23GBImFPgRfeWZ5Xz8dmAXiX84TG+Ozz+R2pZ5dVMKkK9dDwWet Qh4SJ13967S0i75xoQRx1os8IHyaHZuW3GhD4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VpHme89Z0rCPic1Nkuyy0owdmlkiCOT5gaBDWHl46G4=; b=Yxe6H5uwN7yQ5LmYaJfPsn7jXALpBaXhP5eEqTptDoH8oBDqNrNsJEpY2V35iHBUNo XkRGqCzZ15WSDdUQF5QfMwy46t6QUf6C8J9V/V9hZOzgzYqBPPbdar5HAxlJrspwjGrH +IAIAhB02paG6r/L/sjzk/CPBOK8WPwgnT81SD8Lf6/LyTNIVXDD4HP32Hu9tlgEcrDf HvLwTjj7iv7y7qpLtkE3r+UGZlYeyCHiCoaaIuT4dtyVNZniHgHyTxzlHrC6RXujQN5U JCJERKsiGQ7vKgeYk0eSeVqw+Rp7f8Lprm131C+aONpkxK37dD/OCAnpu9u981ZiEtVz svyQ== X-Gm-Message-State: AOAM531pIXwA1dTkDqhuBP+V5W/rX7yuP3F1pq3ygCXkJVlYNwmxZC3F t7aqrqFWLrAhINv0igyR3ryjPQCEY+lUXuV/ X-Google-Smtp-Source: ABdhPJxCeGTTrlirmLKPElioGBW5yBoHIumnAOgnKdkssjvHLUxwf5QMoU2IH89gq2Ykkse9+5hRCA== X-Received: by 2002:aca:a8d6:: with SMTP id r205mr213092oie.77.1625524400156; Mon, 05 Jul 2021 15:33:20 -0700 (PDT) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id u22sm1434938oie.26.2021.07.05.15.33.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jul 2021 15:33:19 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Alper Nebi Yasak Subject: [PATCH 11/22] cros_ec: Allow reading the battery-charge state Date: Mon, 5 Jul 2021 16:32:49 -0600 Message-Id: <20210705223300.2139971-10-sjg@chromium.org> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog In-Reply-To: <20210705223300.2139971-1-sjg@chromium.org> References: <20210705223300.2139971-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean Add a function to read this information from the EC. It is useful for determining whether the battery has enough charge to boot. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- drivers/misc/cros_ec.c | 17 +++++++++++++++++ include/cros_ec.h | 8 ++++++++ 2 files changed, 25 insertions(+) diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c index 7904d5cc72d..0818ef8ad6e 100644 --- a/drivers/misc/cros_ec.c +++ b/drivers/misc/cros_ec.c @@ -1661,6 +1661,23 @@ int cros_ec_get_switches(struct udevice *dev) return ret; } +int cros_ec_read_batt_charge(struct udevice *dev, uint *chargep) +{ + struct ec_params_charge_state req; + struct ec_response_charge_state resp; + int ret; + + req.cmd = CHARGE_STATE_CMD_GET_STATE; + ret = ec_command(dev, EC_CMD_CHARGE_STATE, 0, &req, sizeof(req), + &resp, sizeof(resp)); + if (ret) + return log_msg_ret("read", ret); + + *chargep = resp.get_state.batt_state_of_charge; + + return 0; +} + UCLASS_DRIVER(cros_ec) = { .id = UCLASS_CROS_EC, .name = "cros-ec", diff --git a/include/cros_ec.h b/include/cros_ec.h index 9396b4d2466..9dab6cdf9ba 100644 --- a/include/cros_ec.h +++ b/include/cros_ec.h @@ -652,4 +652,12 @@ int cros_ec_vstore_read(struct udevice *dev, int slot, uint8_t *data); int cros_ec_vstore_write(struct udevice *dev, int slot, const uint8_t *data, size_t size); +/** + * cros_ec_read_batt_charge() - Read the battery-charge state + * + * @dev: CROS-EC device + * @chargep: Return battery-charge state as a percentage + */ +int cros_ec_read_batt_charge(struct udevice *dev, uint *chargep); + #endif