Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp449923lqp; Mon, 10 Jun 2024 08:52:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVKt/VYOQU9ymgznYb8Ap31Pvg2/66eX+oE5YkCMEtFzcZcFIQ0nNqC28xkoK5BhKXLdUCUvLFLHl6apiaeIDuNR7/v+vghAUrX09tIXw== X-Google-Smtp-Source: AGHT+IGZlUhVubXR7vQFMk1YpAX56RBJijqZCdY3srr7McxIGbjX8MlotddEgcS/gfcL73U38d/x X-Received: by 2002:a05:6808:6093:b0:3d1:ffce:2ae1 with SMTP id 5614622812f47-3d210f483b5mr9934782b6e.53.1718034754616; Mon, 10 Jun 2024 08:52:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718034754; cv=pass; d=google.com; s=arc-20160816; b=njB8xV20ROOd0byQ3RqmGddHAWrqmdqOIoRZ6s/9sVjNnNTl3XzO9qc4eQAHYtUn2t 60POVzg7SidFkPE2ZsC6CjHq6A+V4oGQgFe+YyIDtWZinR5cMVSXC8pxVZOhUmVIdwCz GciLK/n/JKWdCeVYJNCHHkZfHe15yxJUzGbYxrwaP7/qTuegWmQT98xwyA29YH5UVKic vKbXSQfnxw/bY9S3bPAAPyIvNG+hHKOmoRTTLo3MHfA4W28vuznfGKhzuckO0po6hHfY cXsreNc9m4Wzjly+MR68elZRF3q3Opk+qwtfhuwm3r7y7fS+wBFhDHY5kc4Gu/2t+LoW i4LQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=8uj3NwVpRomFBIGpH/BD1yefOXMtXgDmlr7ne2bTWXc=; fh=mNAGY4UiCC2gtYBxmMCQKDpXYJDs8SkK6GbJ2jw39Lc=; b=ThGhGTh+4LZW3XSZzQsiL5FKF3v9fCx6f6p/QSBBcfJ0SYYmLv8ScVD4Zssfc45rgU Tml7+27I75m0uQgmy1pcMBEgXXWNUaquC4oW6uqm8F7lGxz51sMcu8HZ3A0AqBlTI3Ux uWiJNVGxjLKSev0O2Iwv+FpyB1wn2omvWYThEvrcTxskXeoWmwPQkBxV6mnC0U1jkQBr R6jWeLixm9AY6logBnN9y5B7sgUkG6D1fXCnaSuZEOFPv1eGbS+MLjXc1AU3NqlaZANe 7s310blznQvbe5VNwjJU2zWkXiZd/ZEmPjSeA2tapq+UamfLCtRZeU46UTSSz+wKRWIJ NaDA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=aOHM2mGL; arc=pass (i=1 spf=pass spfdomain=weissschuh.net dkim=pass dkdomain=weissschuh.net dmarc=pass fromdomain=weissschuh.net); spf=pass (google.com: domain of linux-kernel+bounces-208510-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208510-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=weissschuh.net Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-79550268696si661580285a.244.2024.06.10.08.52.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 08:52:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208510-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=aOHM2mGL; arc=pass (i=1 spf=pass spfdomain=weissschuh.net dkim=pass dkdomain=weissschuh.net dmarc=pass fromdomain=weissschuh.net); spf=pass (google.com: domain of linux-kernel+bounces-208510-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208510-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=weissschuh.net Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 579B01C21A83 for ; Mon, 10 Jun 2024 15:52:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 094B4143757; Mon, 10 Jun 2024 15:52:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="aOHM2mGL" Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5FBAA13E3F2; Mon, 10 Jun 2024 15:52:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718034731; cv=none; b=H/wLSme1oOuf7rkMXdn260IAHR74Cf0jZ7oDBaITpyOlA8B8addwthD3Mv93fRZNhDhVybgU+qbPimRaJNAl977+MaruL3Pey0BYh9975ajb2TiTLmpMrtqKeDl8lYqqZBI13ML76P6vl+z5mslDZs2/pKaNpQrir7hYb8gk2dA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718034731; c=relaxed/simple; bh=wiXThF8Cv8s9BfLtjBMdMwv3BjfaTV7Ak2mbNROgkoo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=f/tquSS5qZbaP1Lwi44QaUuM1S7uQhcpOajcy0LRGD7Vi45RluH/1nAZDTWwIxEkva2Fd1USUBounV+EO+8dSTJNd2h6fX2O2DOC5e5te/Q/XRbaXKiQyIPNGFm+dFtlaiYcQ06OHLNJMsHeEXahqVoo/2XOlDnWLDtUaMWKNRE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=aOHM2mGL; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1718034726; bh=wiXThF8Cv8s9BfLtjBMdMwv3BjfaTV7Ak2mbNROgkoo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=aOHM2mGLnlszY7u+sQzIDhQHoXwsq1HEyRzsTq6itoRH0SpGbE1VUHwyTmVbAWT+4 /h2rgdWK7O1IBJXAuoBjx3Rw7T0Dhfrb2eut7hU7/L1wmq5sFz2eUEGnCxDMWvv161 KFrMKQBxz3sIwuAoRLTdWP5YwVttb6k+0ZvKKJws= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 10 Jun 2024 17:51:07 +0200 Subject: [PATCH v3 2/5] platform/chrome: Update binary interface for EC-based charge control Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20240610-cros_ec-charge-control-v3-2-135e37252094@weissschuh.net> References: <20240610-cros_ec-charge-control-v3-0-135e37252094@weissschuh.net> In-Reply-To: <20240610-cros_ec-charge-control-v3-0-135e37252094@weissschuh.net> To: Benson Leung , Guenter Roeck , Sebastian Reichel , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , "Rafael J. Wysocki" , Len Brown , Robert Moore , Tzung-Bi Shih Cc: chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Mario Limonciello , Dustin Howett , Stephen Horvath , Rajas Paranjpe , linux-acpi@vger.kernel.org, acpica-devel@lists.linux.dev, Matt Hartley , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1718034726; l=2737; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=wiXThF8Cv8s9BfLtjBMdMwv3BjfaTV7Ak2mbNROgkoo=; b=1SsvsC41J3n/vk/ZG8IwOit7MH7m+s2bsFwzf2068otXpRxHxWulpchHzAKYs8HMPQTRcdGg2 NTPpEtMUjvOAHBvHVWMpaw6tpZlNmJuIhewveILqkqRogpcBMrmjDsE X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The charge-control command v2/v3 is more featureful than v1, it additionally supports charge thresholds. The definitions were imported from ChromeOS EC commit 32870d602317 ("squirtle: modify motionsense rotation matrix") Acked-by: Tzung-Bi Shih Signed-off-by: Thomas Weißschuh --- include/linux/platform_data/cros_ec_commands.h | 49 ++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/include/linux/platform_data/cros_ec_commands.h b/include/linux/platform_data/cros_ec_commands.h index ec598057d1da..e574b790be6f 100644 --- a/include/linux/platform_data/cros_ec_commands.h +++ b/include/linux/platform_data/cros_ec_commands.h @@ -3843,16 +3843,61 @@ struct ec_params_i2c_write { * discharge the battery. */ #define EC_CMD_CHARGE_CONTROL 0x0096 -#define EC_VER_CHARGE_CONTROL 1 +#define EC_VER_CHARGE_CONTROL 3 enum ec_charge_control_mode { CHARGE_CONTROL_NORMAL = 0, CHARGE_CONTROL_IDLE, CHARGE_CONTROL_DISCHARGE, + /* Add no more entry below. */ + CHARGE_CONTROL_COUNT, +}; + +#define EC_CHARGE_MODE_TEXT \ + { \ + [CHARGE_CONTROL_NORMAL] = "NORMAL", \ + [CHARGE_CONTROL_IDLE] = "IDLE", \ + [CHARGE_CONTROL_DISCHARGE] = "DISCHARGE", \ + } + +enum ec_charge_control_cmd { + EC_CHARGE_CONTROL_CMD_SET = 0, + EC_CHARGE_CONTROL_CMD_GET, +}; + +enum ec_charge_control_flag { + EC_CHARGE_CONTROL_FLAG_NO_IDLE = BIT(0), }; struct ec_params_charge_control { - uint32_t mode; /* enum charge_control_mode */ + uint32_t mode; /* enum charge_control_mode */ + + /* Below are the fields added in V2. */ + uint8_t cmd; /* enum ec_charge_control_cmd. */ + uint8_t flags; /* enum ec_charge_control_flag (v3+) */ + /* + * Lower and upper thresholds for battery sustainer. This struct isn't + * named to avoid tainting foreign projects' name spaces. + * + * If charge mode is explicitly set (e.g. DISCHARGE), battery sustainer + * will be disabled. To disable battery sustainer, set mode=NORMAL, + * lower=-1, upper=-1. + */ + struct { + int8_t lower; /* Display SoC in percentage. */ + int8_t upper; /* Display SoC in percentage. */ + } sustain_soc; +} __ec_align4; + +/* Added in v2 */ +struct ec_response_charge_control { + uint32_t mode; /* enum charge_control_mode */ + struct { /* Battery sustainer thresholds */ + int8_t lower; + int8_t upper; + } sustain_soc; + uint8_t flags; /* enum ec_charge_control_flag (v3+) */ + uint8_t reserved; } __ec_align4; /*****************************************************************************/ -- 2.45.2