From patchwork Fri Jan 19 13:25:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksij Rempel X-Patchwork-Id: 189560 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp1004715dyb; Fri, 19 Jan 2024 05:27:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IFgKeXkEc4EXSyQGjeKjNan7u/xfSEAYJFoEgkpl0wTRXEfzfDR5ssQfxbmKwA5idqxorlL X-Received: by 2002:a17:902:e54e:b0:1d7:2506:3ec0 with SMTP id n14-20020a170902e54e00b001d725063ec0mr535840plf.82.1705670875633; Fri, 19 Jan 2024 05:27:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705670875; cv=pass; d=google.com; s=arc-20160816; b=wbiRYntMMLKhJvLr5b5SvYed2xxru9X3aJ8Flu7fXELroHoCjsr92DCtSOC2cupSDA DwLX57E0R+S/vL7h7yRVlkSnO2fuitNxjWBJZyOuTGwq/6RfKg1dX1voeJqeLmvIE/pa wbpkn273r0hU4b645QcoqI3I7rqkYEIVVceFjXJOfNtSaxdRJlEyRP/1hyo0PdTTYTJj x03R7qchezAyLZ/+I6E9GgnvuKR+T5CPUwHJYIOUuwTg21OD01x4zttbyN822jDx3wWJ Rg1xlln3mcmBhuLLQ/pHzwMwATDzEHAlrYtBzQYDguh1osydZfFYgF87cw4uXK9IdWsi GqlQ== 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31195-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id b22-20020a170902d89600b001d717e644ecsi1865513plz.419.2024.01.19.05.27.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 05:27:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-31195-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-31195-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31195-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id C099F28626B for ; Fri, 19 Jan 2024 13:27:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E55F554BF7; Fri, 19 Jan 2024 13:25:43 +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_Andersen?= 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 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788525543660526981 X-GMAIL-MSGID: 1788525543660526981 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) {