Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp232630img; Tue, 19 Mar 2019 22:54:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqzwubjbsLaLr8cG4mWvy8nPTuRaxpWcS1sRCCdH6l/FvCPkNY+uPJtNuiA5JX+UFRGVJvjQ X-Received: by 2002:a65:6203:: with SMTP id d3mr5665739pgv.109.1553061292196; Tue, 19 Mar 2019 22:54:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553061292; cv=none; d=google.com; s=arc-20160816; b=VZzvLmC4yV1T28jB9iiiPcgRoBMymX74mrfMx+WygFAqcrJ/mwR6oEx+nMRIwHycq8 Nk2bqt2qSB6t55X/y/QtH4hBjiR+Lehs4FTzoHEUmGWye0q66AppryE/e8JVA7fXvbXL NaH5/x3oKujGDqc/qhEB192tqU9z9M2akLt4wtMmbeCEfC7UYdW49dtdE5IIQvpGmQx8 Ueyi3/7oLpnNKjP2oOkIlY1ZQ48q0EKVBdjbQXStpHOIe+FvLxDElTeeDEqfY/HRjRhb SBmUCwJWoEAkfiITkCh9MbglwxxexfU3WTmJD14raRDd+j3VrWp3qIILJXApkNkuIVav ZCeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=pqUF8GFN4z1VnHFyOOL15AwSLlFMJcjZp7+gzEfYigE=; b=KxyryRnHqR+RSSNeybWk4l3ddL9HYVCJBiBcZel0XRe62X4OWu4VAgx1xHfwsQZC9q QCQLjSczT7ygfCe5PfS9QexGyYW5IVdCIeVcIlj5im399S5xCEHNPKeW/lLYpFWHvF/T 1KW7u27OLwn5qIHVvltfInAUp+OZMjtoGlMcDHMPWEhmnhUgFvASmImeYLSWin6WObj+ pFN9cHO4HcNfMUGRj5bdqtApcz1VlakSZWHiUczCLTtaKhBsxOmhPiLSDYut2Aq8Wrlg /2izXQacsDSqmYgPJbAlwuHmToAIKbu+EKC0SsHg/QjSpwL4Uz5EqeOw5Do5DU3M95YL vkcA== 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 b3si874573pgq.132.2019.03.19.22.54.36; Tue, 19 Mar 2019 22:54: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; 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 S1727185AbfCTFx0 (ORCPT + 99 others); Wed, 20 Mar 2019 01:53:26 -0400 Received: from alexa-out-blr-01.qualcomm.com ([103.229.18.197]:24848 "EHLO alexa-out-blr-01.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725900AbfCTFx0 (ORCPT ); Wed, 20 Mar 2019 01:53:26 -0400 X-IronPort-AV: E=Sophos;i="5.60,247,1549909800"; d="scan'208";a="454358" Received: from ironmsg02-blr.qualcomm.com ([10.86.208.131]) by alexa-out-blr-01.qualcomm.com with ESMTP/TLS/AES256-SHA; 20 Mar 2019 11:23:23 +0530 X-IronPort-AV: E=McAfee;i="5900,7806,9200"; a="7284346" Received: from gkohli-linux.qualcomm.com ([10.204.78.26]) by ironmsg02-blr.qualcomm.com with ESMTP; 20 Mar 2019 11:23:23 +0530 Received: by gkohli-linux.qualcomm.com (Postfix, from userid 427023) id 933EB3B35; Wed, 20 Mar 2019 11:23:22 +0530 (IST) From: Gaurav Kohli To: srinivas.kandagatla@linaro.org, linux-kernel@vger.kernel.org Cc: linux-arm-msm@vger.kernel.org, Shiraz Hashim , Gaurav Kohli Subject: [PATCH v0] nvmem: core: Export nvmem cell info to userspace Date: Wed, 20 Mar 2019 11:23:21 +0530 Message-Id: <1553061201-28894-1-git-send-email-gkohli@codeaurora.org> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Shiraz Hashim Existing nvmem framework export full register space as nvmem binary, but not exporting child node of nvmem which is nvmem cell. Kernel can read the specific cell by using nvmem_cell_read but userspace don't have such provision. Add framework to export nvmem cell as well, So userspace can use it directly. Signed-off-by: Shiraz Hashim Signed-off-by: Gaurav Kohli Co-developed-by: Gaurav Kohli diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index f24008b..e4b6160 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -47,6 +47,7 @@ struct nvmem_cell { int nbits; struct device_node *np; struct nvmem_device *nvmem; + struct bin_attribute attr; struct list_head node; }; @@ -99,6 +100,27 @@ static ssize_t type_show(struct device *dev, return sprintf(buf, "%s\n", nvmem_type_str[nvmem->type]); } +static ssize_t bin_attr_nvmem_cell_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *attr, + char *buf, loff_t pos, size_t count) +{ + struct nvmem_cell *cell; + size_t len; + u8 *data; + + if (attr->private) + cell = attr->private; + else + return -EINVAL; + + data = nvmem_cell_read(cell, &len); + + len = (len > count) ? count : len; + memcpy(buf, data, len); + + return len; +} + static DEVICE_ATTR_RO(type); static struct attribute *nvmem_attrs[] = { @@ -324,6 +346,7 @@ static void nvmem_cell_drop(struct nvmem_cell *cell) { blocking_notifier_call_chain(&nvmem_notifier, NVMEM_CELL_REMOVE, cell); mutex_lock(&nvmem_mutex); + device_remove_bin_file(&cell->nvmem->dev, &cell->attr); list_del(&cell->node); mutex_unlock(&nvmem_mutex); of_node_put(cell->np); @@ -341,8 +364,24 @@ static void nvmem_device_remove_all_cells(const struct nvmem_device *nvmem) static void nvmem_cell_add(struct nvmem_cell *cell) { + int rval; + struct bin_attribute *nvmem_cell_attr = &cell->attr; + mutex_lock(&nvmem_mutex); list_add_tail(&cell->node, &cell->nvmem->cells); + + /* add attr for this cell */ + nvmem_cell_attr->attr.name = cell->name; + nvmem_cell_attr->attr.mode = 0400; + nvmem_cell_attr->private = cell; + nvmem_cell_attr->size = cell->bytes; + nvmem_cell_attr->read = bin_attr_nvmem_cell_read; + rval = device_create_bin_file(&cell->nvmem->dev, nvmem_cell_attr); + if (rval) { + dev_err(&cell->nvmem->dev, + "Failed to create cell binary file %d\n", rval); + } + mutex_unlock(&nvmem_mutex); blocking_notifier_call_chain(&nvmem_notifier, NVMEM_CELL_ADD, cell); } -- Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.