From patchwork Wed May 29 06:27:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13677927 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 59D0715F403 for ; Wed, 29 May 2024 06:27:22 +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=1716964043; cv=none; b=gW9UZk8xGTWFggX+Mh0kyaToTraKxN6s1BkwvF43hu7FCTx330Z2XYtAE4v1Q3ezMoH4CtDpFGrzqTCYSAFgl7NYs0cGvxONrAURvvJD2u7c74VCSjGkWdJsgzLFE5ZcYTvgNDQ/85Q/+Fh1LgjKCty7N6I1NR2+abfyvRHRpjE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716964043; c=relaxed/simple; bh=YXsw9Xicl8EATJ4ZrHMH0cJ6u503P6Q2iTyqNUPD3Zs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Seg8C03WRtUSEyARLnk35eWwBCOd8zJ10HQMWvyebsLWvki/SgZ/KPOBcWutmmufxKLNYILT8Zy8A6VbNRs5l3+tiAbxTcX2ceP8Q3F3mZA85lC8uQadAOqzFwxDPrpmhOwlCxei5dpQeISBdMK/fg19dYqpOhoANReD7BJJ/io= 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=AsTYe+fa; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="AsTYe+fa" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1716964039; bh=YXsw9Xicl8EATJ4ZrHMH0cJ6u503P6Q2iTyqNUPD3Zs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=AsTYe+fafq71rhigQ0nCUQ5bRYUTvFzsk8bNulgzOOQbudjBfXTVbj02dWbJ28MJS SqLL0L8Xr8/NTGvkpp4uKzGle7NovX3w7wNE2/zcIYuDR1Bpi8eR1ZchS8R+PeKhYn oUEJ+4iLrz3Y35cnSR4CFqxD4RYSC0ZvsFBVnlMM= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 29 May 2024 08:27:11 +0200 Subject: [PATCH v4 1/3] platform/chrome: cros_ec_proto: Introduce cros_ec_cmd_readmem() Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240529-cros_ec-hwmon-v4-1-5cdf0c5db50a@weissschuh.net> References: <20240529-cros_ec-hwmon-v4-0-5cdf0c5db50a@weissschuh.net> In-Reply-To: <20240529-cros_ec-hwmon-v4-0-5cdf0c5db50a@weissschuh.net> To: Jean Delvare , Guenter Roeck , Benson Leung , Lee Jones , Tzung-Bi Shih Cc: Guenter Roeck , linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, chrome-platform@lists.linux.dev, Dustin Howett , Mario Limonciello , Moritz Fischer , Stephen Horvath , Rajas Paranjpe , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1716964039; l=2309; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=YXsw9Xicl8EATJ4ZrHMH0cJ6u503P6Q2iTyqNUPD3Zs=; b=+sofws1B8KLLelgmW9aJk2d8gV94HqdSiWSn61jhVzcBoJ33D9eRxoGAG28lYHD8DW2KjbC4y q+ufw94H2odAqWfRlndYmxj8b3zx3INTwPR7j+ApuNKY/gyXvJNKuin X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= To read from the EC memory different mechanism are possible. ECs connected via LPC expose their memory via a ->cmd_readmem operation. Other protocols require the usage of EC_CMD_READ_MEMMAP, which on the other hand is not implemented by LPC ECs. Provide a helper that automatically selects the correct mechanism. Signed-off-by: Thomas Weißschuh Reviewed-by: Guenter Roeck --- drivers/platform/chrome/cros_ec_proto.c | 27 +++++++++++++++++++++++++++ include/linux/platform_data/cros_ec_proto.h | 2 ++ 2 files changed, 29 insertions(+) diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c index 945b1b15a04c..daddc8731cef 100644 --- a/drivers/platform/chrome/cros_ec_proto.c +++ b/drivers/platform/chrome/cros_ec_proto.c @@ -1035,3 +1035,30 @@ int cros_ec_cmd(struct cros_ec_device *ec_dev, return ret; } EXPORT_SYMBOL_GPL(cros_ec_cmd); + +/** + * cros_ec_cmd_readmem - Read from EC memory. + * + * @ec_dev: EC device + * @offset: Is within EC_LPC_ADDR_MEMMAP region. + * @size: Number of bytes to read. + * @dest: EC command output data + * + * Return: >= 0 on success, negative error number on failure. + */ +int cros_ec_cmd_readmem(struct cros_ec_device *ec_dev, u8 offset, u8 size, void *dest) +{ + struct ec_params_read_memmap params = {}; + + if (!size) + return -EINVAL; + + if (ec_dev->cmd_readmem) + return ec_dev->cmd_readmem(ec_dev, offset, size, dest); + + params.offset = offset; + params.size = size; + return cros_ec_cmd(ec_dev, 0, EC_CMD_READ_MEMMAP, + ¶ms, sizeof(params), dest, size); +} +EXPORT_SYMBOL_GPL(cros_ec_cmd_readmem); diff --git a/include/linux/platform_data/cros_ec_proto.h b/include/linux/platform_data/cros_ec_proto.h index 8865e350c12a..1ddc52603f9a 100644 --- a/include/linux/platform_data/cros_ec_proto.h +++ b/include/linux/platform_data/cros_ec_proto.h @@ -261,6 +261,8 @@ int cros_ec_get_sensor_count(struct cros_ec_dev *ec); int cros_ec_cmd(struct cros_ec_device *ec_dev, unsigned int version, int command, const void *outdata, size_t outsize, void *indata, size_t insize); +int cros_ec_cmd_readmem(struct cros_ec_device *ec_dev, u8 offset, u8 size, void *dest); + /** * cros_ec_get_time_ns() - Return time in ns. *