From patchwork Wed Jul 26 09:34:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 108747 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp582747qge; Wed, 26 Jul 2017 02:35:53 -0700 (PDT) X-Received: by 10.98.104.133 with SMTP id d127mr274942pfc.193.1501061752902; Wed, 26 Jul 2017 02:35:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501061752; cv=none; d=google.com; s=arc-20160816; b=OLdQwbNXtNKK6Ejwt06vduXjovXWIMYSDd6sGxtvZyxz8dMeXQxDkgCgJTqwntugGX 0LCUpLmWh1gXh1CD48Fkq6JKuE3epzBqLyFv7YB4TMJB+T4HefglHAgoiFE7KOwW77Tf D7ZB5PFYih/05XyH+KpNNyCF5+iYr4+iz9sIyO9rCxx+b5hsdqWYD1C0QSkNubzdYHRl joWWjo5wSTc8wzsnIYfWPuYNUHLnug2BWPy4zKnog3sgjeAK15uxlZxobJnQLc5YIVMG 4MxebwJXXx6R0i5Q7W+j/Kh2yvATUTJbxgK0b2Sca72JOZq1PuLMo0+VCbJd4jqerpYj vsDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=GgMcymkbot3/mx7qd4BVe1HJUoDDuYZvs4u529KanNE=; b=b8PpVq0P7q1E9SOSfjN5yL512Tzqy8Z6EkeYmAdbkOg8lIuTEmwlOuHbdLkQuWEVJ9 wtQubNqM+AwuSYLPZtelqwdoTmF6JkFgGW0H5/9YQc4d5t68khh4Odpr7A4UocsayRwU FrMHQcQC9bsJqK0e63dsC9MfBkM92OyDYgxgoOF6cN1GBxsTyVSTouH9CwdTNPrzcAm/ u4Ezvh3/QEUB1r+h2ifJzAn72VpIEizniRcRdHlkW7Ju0njV7nzxsath8+qjxQuDDOAE FL4HmFvZh/EBGjYzlwMawK3Q52ZGyYz3A67yPvR0trHrZXAMDlDhuDtzvFniMXbUV0tm mwLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=beZsxPhP; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a90si5216868pli.654.2017.07.26.02.35.52; Wed, 26 Jul 2017 02:35:52 -0700 (PDT) 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; dkim=pass header.i=@linaro.org header.b=beZsxPhP; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751693AbdGZJfs (ORCPT + 26 others); Wed, 26 Jul 2017 05:35:48 -0400 Received: from mail-io0-f179.google.com ([209.85.223.179]:38335 "EHLO mail-io0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751466AbdGZJfA (ORCPT ); Wed, 26 Jul 2017 05:35:00 -0400 Received: by mail-io0-f179.google.com with SMTP id g13so65470763ioj.5 for ; Wed, 26 Jul 2017 02:34:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GgMcymkbot3/mx7qd4BVe1HJUoDDuYZvs4u529KanNE=; b=beZsxPhPFJARDgjY7Fkm3mES9XlNVSLq02OH0nuy5Nu/joAXcFPaYq2y57K28vFbXF Rn5uPSksdZyvS8gZ/EsB6Vfy8YEsZK8r9PQB06RlXNUCgQK3cXEqCbowG6/hincRE6mZ a658JVDWc8VqmyIXw9o6nP74STAQMJrDSnwxw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GgMcymkbot3/mx7qd4BVe1HJUoDDuYZvs4u529KanNE=; b=QjgMIibIEmpY852MLQME7mwHxx7VHvrC4amWawBCiZ9EjQ85H+B4yfe6nFkHSfzXpw fc3acxpkGacalSuMU7ONQk4eedlqXP08zAF2f5J4hDLrgslctzGbC7Kvh0xtz1WawknB SS6B33Lmyttl2Oo8MY77wUaTv/MitH5EU/cxS8F9XJjzKKwMD5EYM5ADKNivYaAOaZv8 kWH9jJyn61+2/UEHvSPyWxyClejKjkyBR4L1W4XAkw8QM02ml9sxwa+ecLX0ryykM8A4 BHMqzDQ58G0Vk47XLitjzxEVpw02AuLiiQVzk+6OZHE+x7/JSb7KcGvPSrwZJu8qmaJ1 XXjQ== X-Gm-Message-State: AIVw112VWEyVcL7ebsTuy4VHxhk0PK4uUxZQVW2VMTlzR3g7xCUFBau+ j1trsh7c4FCEHRCs X-Received: by 10.107.136.154 with SMTP id s26mr365096ioi.139.1501061698764; Wed, 26 Jul 2017 02:34:58 -0700 (PDT) Received: from localhost.localdomain (static.8.26.4.46.clients.your-server.de. [46.4.26.8]) by smtp.gmail.com with ESMTPSA id c195sm7837169ioe.42.2017.07.26.02.34.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Jul 2017 02:34:58 -0700 (PDT) From: srinivas.kandagatla@linaro.org To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, Leonard Crestez , Srinivas Kandagatla Subject: [PATCH 4/6] nvmem: core: Add nvmem_cell_read_u32 Date: Wed, 26 Jul 2017 11:34:46 +0200 Message-Id: <20170726093448.2564-5-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170726093448.2564-1-srinivas.kandagatla@linaro.org> References: <20170726093448.2564-1-srinivas.kandagatla@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Leonard Crestez This function does a quick and easy read of an u32 value without any kind of resource management code on the consumer side. Signed-off-by: Leonard Crestez Reviewed-by: Shawn Guo Signed-off-by: Srinivas Kandagatla --- drivers/nvmem/core.c | 37 +++++++++++++++++++++++++++++++++++++ include/linux/nvmem-consumer.h | 7 +++++++ 2 files changed, 44 insertions(+) -- 2.9.3 diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index b0c6033..72a60dc 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -1111,6 +1111,43 @@ int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len) EXPORT_SYMBOL_GPL(nvmem_cell_write); /** + * nvmem_cell_read_u32() - Read a cell value as an u32 + * + * @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_u32(struct device *dev, const char *cell_id, u32 *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_u32); + +/** * nvmem_device_cell_read() - Read a given nvmem device and cell * * @nvmem: nvmem device to read from. diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h index c2256d7..efafccf 100644 --- a/include/linux/nvmem-consumer.h +++ b/include/linux/nvmem-consumer.h @@ -35,6 +35,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_u32(struct device *dev, const char *cell_id, u32 *val); /* direct nvmem device read/write interface */ struct nvmem_device *nvmem_device_get(struct device *dev, const char *name); @@ -85,6 +86,12 @@ static inline int nvmem_cell_write(struct nvmem_cell *cell, return -ENOSYS; } +static inline int nvmem_cell_read_u32(struct device *dev, + const char *cell_id, u32 *val) +{ + return -ENOSYS; +} + static inline struct nvmem_device *nvmem_device_get(struct device *dev, const char *name) {