Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp1000117rdb; Fri, 19 Jan 2024 05:26:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IGgWm8e+FxR1+YG13VrK1ck/bp154n85kcXYQFZSAG3o6Ql4dxcodYtYQVGR9sxOt7adEr6 X-Received: by 2002:a17:907:7f8d:b0:a28:a70d:6c49 with SMTP id qk13-20020a1709077f8d00b00a28a70d6c49mr1806783ejc.127.1705670804003; Fri, 19 Jan 2024 05:26:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705670803; cv=pass; d=google.com; s=arc-20160816; b=NwzYmvM8jukE8jt6lmPHazbtC5cyFERetskwTgYAhLIJgZKPgM5xaGe/5NhFA3E7Jo TAYv3AI4+DvSDXqsY6oZPH3ruUXvFcvkeFt3/bOr0Z55QmSoD2e79LrfAQvmrVKpKjHt Rhm+Ewt6krmW7vH203DFIQSaefG/QhK9Fh4W3nvwbxjGfiNN24rN8AP+7v/KGfH+GhsR A/1u+b9FoyWNwbMjwGjySzhZjfv01cNWWf5puJcLvWRqN8IqaqkverFq0RUij3Znp9NW XJz5dSwk0nEWj0pZ3VmoBMTQlOGw0Jq8NPRrIrk08W9loSBSjnfGxDhLPGB4QUW2f6l2 W7nQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=aQOHL9INizumnSzRcpfP7Bm6wQgyvN+k/JMwluUWIvM=; fh=cTOyeHIiotxFveWD397Up69SLR8Dqpy9YboYIfW0A00=; b=Gt1Lbm/xgpMZnVh8UOh2wciXzInPsL3840ww+GNLhokyAbNPo4a1yrU/Rk21JiATi6 B+ZhDT/o+g3O767/9nYTjJ9IQLDsvx6KMPENPWdWsFawbA0bMZWaaDjYp5udEZXZxR3e 374BgA4wpvXK4yVX4SgbY1iw/IXmMI8ED2WRGFwp+bkn3PPiwz0LTACd2qhzR+uDxlg0 fvX4gFk35l5+7s/jpjUc/adXG7KlOUTxJHlGhgf7+r6ULwZ4limsRDXryAjlcJIcO/im OBIBh15rfIvO+YMcNNn6ukffDAkxranCxzg/EFetBBqtZ2Br/iE/6L/Psr46wV3TyN5i t79w== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-31195-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31195-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 16-20020a170906059000b00a2a20ab96f9si7377627ejn.338.2024.01.19.05.26.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 05:26:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-31195-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-31195-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31195-linux.lists.archive=gmail.com@vger.kernel.org" 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 96F821F224B7 for ; Fri, 19 Jan 2024 13:26:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9EAAE5466A; Fri, 19 Jan 2024 13:25:42 +0000 (UTC) Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 A9A0C52F9E for ; Fri, 19 Jan 2024 13:25:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705670742; cv=none; b=rlnNtT0chRH8QQ8sNTiOZ1CCNqaivX+eaBs556MnAJqPCRW3WV4Z4Xs0970pRBFGYvlFF5YokKXB85hd55eA120yAWxLw/BpEzr79pWKc0BeQCLFZqv1QfktiWyHQKbAiq7VYOPZ/ZunJWyf9HI5klov1h/6FM717MkYaQL0glM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705670742; c=relaxed/simple; bh=XRisp6Vk9LcyDYqrO7hm1pl+pjDkrGL7bL4CcMKtXaY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VdHJ/gfaY0sMMtMEmNEPY+9u8MBOIR3DhpRWxDdvG2DrWgpe5X8bIdTWi4Nt32Kexh8V815kQwjt1flHFDcNGMKtBi+Jm9+C1KM5Rz5H46L6Rugqkxh9vkYQR6KlCB81SEgp+DdarSPXtphQ0pxj90UcXae7K4KML3DHVaWIydY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rQos7-00074I-C2; Fri, 19 Jan 2024 14:25:23 +0100 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rQos6-000viM-7a; Fri, 19 Jan 2024 14:25:22 +0100 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1rQos6-00F98B-0X; Fri, 19 Jan 2024 14:25:22 +0100 From: Oleksij Rempel To: Sebastian Reichel , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Srinivas Kandagatla Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, Liam Girdwood , Mark Brown , "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, =?UTF-8?q?S=C3=B8ren=20Andersen?= Subject: [RFC PATCH v1 4/7] nvmem: provide consumer access to cell size metrics Date: Fri, 19 Jan 2024 14:25:18 +0100 Message-Id: <20240119132521.3609945-5-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240119132521.3609945-1-o.rempel@pengutronix.de> References: <20240119132521.3609945-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Add nvmem_cell_get_size() function to provide access to cell size metrics. In some cases we may get cell size less as consumer would expect it. So, nvmem_cell_write() would fail with incorrect buffer size. Signed-off-by: Oleksij Rempel --- drivers/nvmem/core.c | 25 +++++++++++++++++++++++++ include/linux/nvmem-consumer.h | 7 +++++++ 2 files changed, 32 insertions(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index bf42b7e826db..6c5b785b804b 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -1753,6 +1753,31 @@ int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len) EXPORT_SYMBOL_GPL(nvmem_cell_write); +/** + * nvmem_cell_get_size() - Get the size of a given nvmem cell + * @cell: nvmem cell to be queried. + * @bytes: Pointer to store the size of the cell in bytes. Can be NULL. + * @bits: Pointer to store the size of the cell in bits. Can be NULL. + * + * Return: 0 on success or negative on failure. + */ +int nvmem_cell_get_size(struct nvmem_cell *cell, size_t *bytes, size_t *bits) +{ + struct nvmem_cell_entry *entry = cell->entry; + + if (!entry->nvmem) + return -EINVAL; + + if (bytes) + *bytes = entry->bytes; + + if (bits) + *bits = entry->nbits; + + return 0; +} +EXPORT_SYMBOL_GPL(nvmem_cell_get_size); + static int nvmem_cell_read_common(struct device *dev, const char *cell_id, void *val, size_t count) { diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h index 6ec4b9743e25..a174b05514b4 100644 --- a/include/linux/nvmem-consumer.h +++ b/include/linux/nvmem-consumer.h @@ -56,6 +56,7 @@ void nvmem_cell_put(struct nvmem_cell *cell); void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell); void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len); int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len); +int nvmem_cell_get_size(struct nvmem_cell *cell, size_t *bytes, size_t *bits); int nvmem_cell_read_u8(struct device *dev, const char *cell_id, u8 *val); int nvmem_cell_read_u16(struct device *dev, const char *cell_id, u16 *val); int nvmem_cell_read_u32(struct device *dev, const char *cell_id, u32 *val); @@ -127,6 +128,12 @@ static inline int nvmem_cell_write(struct nvmem_cell *cell, return -EOPNOTSUPP; } +static inline int nvmem_cell_get_size(struct nvmem_cell *cell, size_t *bytes, + size_t *bits) +{ + return -EOPNOTSUPP; +} + static inline int nvmem_cell_read_u8(struct device *dev, const char *cell_id, u8 *val) { -- 2.39.2