Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp449941lqp; Mon, 10 Jun 2024 08:52:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV/05UYwuLoOL1rIVMhwqfM3Zl2EfHt3801w8FcvcVzx6SfkDEwPQkKmMHmg0oKlbIVSFfnysUhGx0bYixwoRLp9xUIm9JazvBQEnonmA== X-Google-Smtp-Source: AGHT+IFDt/ofzbhisDHJmcqbgHsUpl7pRcrrAdmQEoZccUWiKjqzKGw1jA9E8UhpVW6qQWzxI2ze X-Received: by 2002:a05:620a:2720:b0:795:fc87:a3 with SMTP id af79cd13be357-795fc870370mr342181385a.17.1718034756632; Mon, 10 Jun 2024 08:52:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718034756; cv=pass; d=google.com; s=arc-20160816; b=jEXdtRG40ovjHXj5TTkuNUChg3DSWtZRyhJPeE1/CMGo+yS872Sw02OhYy1dwU9Td8 RhFdK8ZrPCM6jPYq2ypntOuNlhkziphFBlWlozbEwTo2K1xP3vlLSJcpYb4XFmjBCp8L u2urBnmhP1w9/FOuWBDiKl2fDHiU8jazaGFxAYzggsNxVspiQmmRgnkeK1cC0OfIEFq2 XoLeAP8pJMqZUBK4POXRfTdM0CFMM0GCOLTLiTCdaHXJe9twiLqZfFkUSfDEoK61Td0r d0jBNN8lOc32lJWaLJdZfhfCTDTCUGlsfFz4if8TfX/3bYCMJHFAZTa914q59kHLb1ld TOYg== 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=jVfAOkn9cXVkOK1eZ3NAs8BbbPvpmGLuqhMvU27gVLo=; fh=mNAGY4UiCC2gtYBxmMCQKDpXYJDs8SkK6GbJ2jw39Lc=; b=P4irTz0cY5RMaemB5C2RwH6tSHWLn7UQV14LFa2XWCeaPwHh/WR+QdtgNI12FJS+88 3jFhlGq0dgT9JzQN1tjbBgIrvRkaQdkZBn7e3yr4P90EKG+/K6nl/tv6LijdMCC5867r qBNICH8KberrTfep4d8lYVKMeAiVbUlL/xy8Y6eU9whWvXymIZbzF/GpcBuFH4T7yHVr epad1JBDFW6h9mqq+LwNZlBY9nQc5Ny4LiwB9CbBewGrLTtHG6jzuFsj5HFl4sf0oCFl S9SldBccfwoBAIHroxYlxSjlSQkoZIIcB/Z27OePm3q5wPPaA2tysFzI05JEzMlWnV/N Q+BA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=GVWNEYq4; 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-208511-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208511-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-7955dd9da5esi459834385a.752.2024.06.10.08.52.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 08:52:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208511-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=GVWNEYq4; 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-208511-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208511-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 5E8C41C21C28 for ; Mon, 10 Jun 2024 15:52:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2F921143885; 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="GVWNEYq4" 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 BF92D13FD84; 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=GjHT4WqMPI1bp9haXy5p4YY4mgTjtZMAGcHokvo3l1rjjaZLp+TkEH6K03iSIienBHBUwA+/gY9BD9ZxjR8g2f4HR1OQRP8SPa4BYDNCPSpF9ykb7dcu8UDtn+xQnwchZKI/98OlTnLckkVgaYyw13GXHbHITw95S8Kbif4O1GA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718034731; c=relaxed/simple; bh=fw/y4pJzNvdZK5afG+PBEc6PoUftleG4LWfjkyyWgdE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lePg21Xo9Vff2TOg0gwEMlIFL83TrXEr07QqStGw8lsz4xA9Qnlsmo/CvA+NV1wkN+eys8wVZh+hyooS5EtbpO/724k4hEEVOe2tjzLLu3W/BauH9L0w8hy0G5vtAOQC+bf+/CLJEMKCOc7XXXkZF9XmHf14TRuCyIiyt6ttzLE= 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=GVWNEYq4; 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=1718034727; bh=fw/y4pJzNvdZK5afG+PBEc6PoUftleG4LWfjkyyWgdE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=GVWNEYq4y+p2k1nI1DUXu7alKrv2JzMLdd7m1xEYzSdZPco7wja8EFfrCcprjytw/ EolLTnczB1aUEbmoq3VqgAq1en1p0ifc3aYwylU4wMucr9gcnQt15PvtkyZ8ovW1OU Cy2feObWyJHw4bgYSj7PEpZVKihVA7RuMSBMup4I= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 10 Jun 2024 17:51:08 +0200 Subject: [PATCH v3 3/5] platform/chrome: cros_ec_proto: Introduce cros_ec_cmd_versions() 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-3-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=2290; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=fw/y4pJzNvdZK5afG+PBEc6PoUftleG4LWfjkyyWgdE=; b=YwRtoGnULOkQW4zC7aYLAfiJtPtABdChOCDtEiivHlKe43kEW31FZZYr/2i5RDBLTZ/6hSZ8+ 0ubd9utJXmHBNaKggVI2w2zDtjYRcWiUroX+AJrud72Oq4MN0Yz7I5J X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Retrieving the supported versions of a command is a fairly common operation. Provide a helper for it. If the command is not supported at all the EC returns -EINVAL/EC_RES_INVALID_PARAMS. This error is translated into an empty version mask as that is easier to handle for callers and they don't need to know about the error details. Signed-off-by: Thomas Weißschuh --- drivers/platform/chrome/cros_ec_proto.c | 26 ++++++++++++++++++++++++++ include/linux/platform_data/cros_ec_proto.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c index fe68be66ee98..9cfe885a5301 100644 --- a/drivers/platform/chrome/cros_ec_proto.c +++ b/drivers/platform/chrome/cros_ec_proto.c @@ -1069,3 +1069,29 @@ int cros_ec_cmd_readmem(struct cros_ec_device *ec_dev, u8 offset, u8 size, void ¶ms, sizeof(params), dest, size); } EXPORT_SYMBOL_GPL(cros_ec_cmd_readmem); + +/** + * cros_ec_cmd_versions - Get supported version mask. + * + * @ec_dev: EC device + * @cmd: Command to test + * + * Return: version mask on success, negative error number on failure. + */ +int cros_ec_cmd_versions(struct cros_ec_device *ec_dev, u16 cmd) +{ + struct ec_params_get_cmd_versions_v1 req = {}; + struct ec_response_get_cmd_versions resp; + int ret; + + req.cmd = cmd; + ret = cros_ec_cmd(ec_dev, 1, EC_CMD_GET_CMD_VERSIONS, + &req, sizeof(req), &resp, sizeof(resp)); + if (ret == -EINVAL) + return 0; /* Command not implemented */ + else if (ret < 0) + return ret; + else + return resp.version_mask; +} +EXPORT_SYMBOL_GPL(cros_ec_cmd_versions); diff --git a/include/linux/platform_data/cros_ec_proto.h b/include/linux/platform_data/cros_ec_proto.h index 6e9225bdf903..98ab5986f543 100644 --- a/include/linux/platform_data/cros_ec_proto.h +++ b/include/linux/platform_data/cros_ec_proto.h @@ -263,6 +263,8 @@ int cros_ec_cmd(struct cros_ec_device *ec_dev, unsigned int version, int command int cros_ec_cmd_readmem(struct cros_ec_device *ec_dev, u8 offset, u8 size, void *dest); +int cros_ec_cmd_versions(struct cros_ec_device *ec_dev, u16 cmd); + /** * cros_ec_get_time_ns() - Return time in ns. * -- 2.45.2