Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp455489img; Thu, 28 Feb 2019 02:23:37 -0800 (PST) X-Google-Smtp-Source: AHgI3IYKhhk+AN5afhKpbCgtoOZR99yJpl9eSw14TAaUirkcw14q1NEUBaHxQj41qeQRfzeijxox X-Received: by 2002:a62:aa08:: with SMTP id e8mr6603302pff.139.1551349417751; Thu, 28 Feb 2019 02:23:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551349417; cv=none; d=google.com; s=arc-20160816; b=v2lGTZwDARq5WvtwIOjTz1VVGzfdpgWeZSatbbjurqDvDRPX7oSC7OkJUJK/GxGoPP D4rh95ygL05zUkJcCx2nxX5+0sPftqYtBWBLT+nENJ975TLSW8ANmjwRtjspjs6r0eM9 tY/snURnfxka42u/fjlrgW+nDTrYsgM6sf1YrIHK/7nkfL0roxPbhpejmLS9EbbsFMeI DwgJy+Cm2p0vRecpI5sWagSolK3v5y23Sie7epZgst/lS7xuzPvZsYfbW9npU+nizaHy nMCRq8/wmqE5VEMCvZvY3uyB0/6smjHs8bn/NtZSTLOdJbDmzYiYTpkrlOYq8g4H8u5Y 91kQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=RDxx0ZnPQgPcPwZAbp8H+2uiymYuC+zeWalHQoxnksk=; b=cNJijfGgja0AXP68RXglzypL/QOIxPnJFPvg9UEjgnDgXAbNbRVIEJbKWepsXspRb6 Fd0NUSHppcwbS+Wj6svui1ZJr7dLJUUBbiZhLDU4FHvkCvwleLWUxTF6LuY3zYBYmZeq MOLYwESmTCFHZmGj0DcatZiiVrEe9/WoI9ic6v83B64rrF+yK21PdDnHGplDfBffLZBf g5O7brZGpKD8K7jHtGurkvkCsE8M6vZ9AAjdyI7K7Ksf+9EU3VggrySqMLeuFcvnu8D4 R9PDo34PD6vqugM9ZXNB/iUz5s5b9JRLeQFaOZPB4vLQ5uCnI6j6E/cTdJ0DPy1yWPNq w32w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e20si17022514pfi.237.2019.02.28.02.23.22; Thu, 28 Feb 2019 02:23:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732460AbfB1KWr (ORCPT + 99 others); Thu, 28 Feb 2019 05:22:47 -0500 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:36482 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732285AbfB1KWr (ORCPT ); Thu, 28 Feb 2019 05:22:47 -0500 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx08-00178001.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x1SAHtTx007035; Thu, 28 Feb 2019 11:20:08 +0100 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2qtwxpcm7w-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 28 Feb 2019 11:20:08 +0100 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 0B3A241; Thu, 28 Feb 2019 10:20:07 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag5node3.st.com [10.75.127.15]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id BC3B62C4A; Thu, 28 Feb 2019 10:20:06 +0000 (GMT) Received: from localhost (10.75.127.50) by SFHDAG5NODE3.st.com (10.75.127.15) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Thu, 28 Feb 2019 11:20:06 +0100 From: Fabrice Gasnier To: , , CC: , , , , , , , Subject: [PATCH v2 4/6] nvmem: core: add nvmem_cell_read_u16 Date: Thu, 28 Feb 2019 11:19:54 +0100 Message-ID: <1551349196-8956-5-git-send-email-fabrice.gasnier@st.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1551349196-8956-1-git-send-email-fabrice.gasnier@st.com> References: <1551349196-8956-1-git-send-email-fabrice.gasnier@st.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.75.127.50] X-ClientProxiedBy: SFHDAG8NODE3.st.com (10.75.127.24) To SFHDAG5NODE3.st.com (10.75.127.15) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-02-28_05:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add nvmem_cell_read_u16() helper to ease read of an u16 value on consumer side. This is inspired by nvmem_cell_read_u32() function. This helper is useful on stm32 that has 16 bits data cells stored in non volatile memory. Signed-off-by: Fabrice Gasnier --- drivers/nvmem/core.c | 37 +++++++++++++++++++++++++++++++++++++ include/linux/nvmem-consumer.h | 7 +++++++ 2 files changed, 44 insertions(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index f7301bb..5bd48ed 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -1331,6 +1331,43 @@ int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len) EXPORT_SYMBOL_GPL(nvmem_cell_write); /** + * nvmem_cell_read_u16() - Read a cell value as an u16 + * + * @dev: Device that requests the nvmem cell. + * @cell_id: Name of nvmem cell to read. + * @val: pointer to output value. + * + * Return: 0 on success or negative errno. + */ +int nvmem_cell_read_u16(struct device *dev, const char *cell_id, u16 *val) +{ + struct nvmem_cell *cell; + void *buf; + size_t len; + + cell = nvmem_cell_get(dev, cell_id); + if (IS_ERR(cell)) + return PTR_ERR(cell); + + buf = nvmem_cell_read(cell, &len); + if (IS_ERR(buf)) { + nvmem_cell_put(cell); + return PTR_ERR(buf); + } + if (len != sizeof(*val)) { + kfree(buf); + nvmem_cell_put(cell); + return -EINVAL; + } + memcpy(val, buf, sizeof(*val)); + kfree(buf); + nvmem_cell_put(cell); + + return 0; +} +EXPORT_SYMBOL_GPL(nvmem_cell_read_u16); + +/** * nvmem_cell_read_u32() - Read a cell value as an u32 * * @dev: Device that requests the nvmem cell. diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h index 312bfa5..8f8be5b 100644 --- a/include/linux/nvmem-consumer.h +++ b/include/linux/nvmem-consumer.h @@ -61,6 +61,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_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); /* direct nvmem device read/write interface */ @@ -122,6 +123,12 @@ static inline int nvmem_cell_write(struct nvmem_cell *cell, return -EOPNOTSUPP; } +static inline int nvmem_cell_read_u16(struct device *dev, + const char *cell_id, u16 *val) +{ + return -EOPNOTSUPP; +} + static inline int nvmem_cell_read_u32(struct device *dev, const char *cell_id, u32 *val) { -- 2.7.4