From patchwork Fri May 11 11:06:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 135523 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp719212lji; Fri, 11 May 2018 04:09:40 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo8nVVZ1dVgxxqkmeSn9VURhhA60Dcn3NdgZvz/iTYSC/famyYD+/GYuh76PuLiKSv1KJhX X-Received: by 2002:a63:7e08:: with SMTP id z8-v6mr171716pgc.383.1526036980084; Fri, 11 May 2018 04:09:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526036980; cv=none; d=google.com; s=arc-20160816; b=AlVvsdVqE2Sje89fzlbdYrKjAOD6+zVt90XV0ws/5Yt1+6ily/WcCOVc33GMnyK5vv hrCseuGheIUhRNKdgenIOxQSRjRjmL8+E6h/NqyG1mjhcJMCmzT2umH6iEIs5yvlb2UT 6WvZ50jdhP2Rz6TZna1Tra4ONyVDSThx7Ehq15O+OqsAlWlWKRe+cY2Xe3rs0xBEfqkf Z/SimJ9j78YIJUCTLVSyu3wgYM6JAzw2GnJG1gFGkenWBRxiKLqsx0x/5mkA4Ata+J8g fAIDzx2MU4kGv8qGyVyVxiszuCwhtRiVm79skKBanvWQaiX+uwgQR2Q2JtFBpxv2qcNx wQTQ== 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=SzJUKBPNwe/3NehlMvPVKfMBKPVrmxN/Paoe95Wq8jY=; b=HQ+ZS86dEmv2VozleDl5Mec1rtXox+/VMguo3HtvpnMV4sDxoXpGjPMJN+rEPdCtwS +YeNbLQwo/IyL5HcByZ1Uk3FW1B2SL0pYxAjKDnAPoPIcf9pbn+o4yOrvZ7rXnxcY395 iu1oYOsBEzOfA9Kmv8bBqttQIyboBS85qoXEndy82bH3hKyQ13yKV9LXQ4X0gRAQ9fQf enygZPf4qpqTigpaXfUXnFIG4GxVz6s72POxHgVQ6tBozxLhMUIb3DuUtQI5mBO8yhC3 CRJYHy9j6XKEXA5jYIPRZIg6W7ZSKlSHpOF4KAh4PAiiKiRJYfIUDRv4MxYWXJHnCwJr PcAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KrXt64vA; 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 82-v6si3059791pfs.40.2018.05.11.04.09.39; Fri, 11 May 2018 04:09:40 -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.s=google header.b=KrXt64vA; 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 S1753467AbeEKLJi (ORCPT + 29 others); Fri, 11 May 2018 07:09:38 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:38861 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753372AbeEKLJb (ORCPT ); Fri, 11 May 2018 07:09:31 -0400 Received: by mail-wr0-f195.google.com with SMTP id 94-v6so4949633wrf.5 for ; Fri, 11 May 2018 04:09:30 -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=SzJUKBPNwe/3NehlMvPVKfMBKPVrmxN/Paoe95Wq8jY=; b=KrXt64vAVv0V2HpDysdipe1/xucwktRGpYBRKz/MDidhFw6E3M5YQxnBaMtyDFc/Bq NFEunrnw3uZWlQkb9S5fhUaDwfQAiWYKL3s+KCueqHRNMtp9QKMSafARWyewrjfhLv70 o597jSW3JtoFYB6vg6rTuAIaGWtHjHHfgb4LU= 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=SzJUKBPNwe/3NehlMvPVKfMBKPVrmxN/Paoe95Wq8jY=; b=Te5jloreQX9jyt9RFE0+GzMCCDL7It4EX81YQ062VxRs2tfpb0HZpItLvBjedQhCV4 XLwWaye5iqjVga+sbRAnXq+dx+2zzx/spu1hRvlBblcR2YP345x3+4D0LIAUcxGYF00E wkjih0UdbqYyISm0qMxDR+bpFzhDlejQIqCEElMNilIJJUOid383FaUROkPSXp/dJSvZ KgMXjyQEF1lXwYaZkDB8uOl0xrr0meOu+dpQN/oJ4MTGo/LlEMBHjVZZzY/48LjQn6MS 4xEwKyKgzOW/qC7IVepivggN5dkfNpReJXBaYV4vJSLqkw3J8vZbfW3X2DwN4HOw7Y1N YqsQ== X-Gm-Message-State: ALKqPwfI+/8wKAukOZ4IUaKMidnfw0DSNa5UKh2QoaS0wL5F/2R1dLnE oU21Lfau61+2kEJb9luJWBD1frefdkA= X-Received: by 2002:adf:a789:: with SMTP id j9-v6mr3980040wrc.95.1526036969776; Fri, 11 May 2018 04:09:29 -0700 (PDT) Received: from localhost.localdomain (cpc90716-aztw32-2-0-cust92.18-1.cable.virginm.net. [86.26.100.93]) by smtp.gmail.com with ESMTPSA id a129-v6sm714047wme.34.2018.05.11.04.09.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 11 May 2018 04:09:29 -0700 (PDT) From: Srinivas Kandagatla To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, srinivas.kandagatla@linaro.org, Andrew Lunn Subject: [PATCH 1/8] drivers: nvmem: Export nvmem_add_cells() Date: Fri, 11 May 2018 12:06:56 +0100 Message-Id: <20180511110703.4924-2-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180511110703.4924-1-srinivas.kandagatla@linaro.org> References: <20180511110703.4924-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: Andrew Lunn Not all platforms use device tree. It is useful to be able to add cells to a NVMEM device from code. Export nvmem_add_cells() so making this possible. This required changing the parameters a bit, so that just the cells and the number of cells are passed, not the whole nvmem config structure. Signed-off-by: Andrew Lunn Reviewed-by: Andrey Smirnov Signed-off-by: Srinivas Kandagatla --- drivers/nvmem/core.c | 24 +++++++++++++++++------- include/linux/nvmem-provider.h | 11 +++++++++++ 2 files changed, 28 insertions(+), 7 deletions(-) -- 2.16.2 diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index b05aa8e81303..b1c95ef78544 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -353,18 +353,27 @@ static int nvmem_cell_info_to_nvmem_cell(struct nvmem_device *nvmem, return 0; } -static int nvmem_add_cells(struct nvmem_device *nvmem, - const struct nvmem_config *cfg) +/** + * nvmem_add_cells() - Add cell information to an nvmem device + * + * @nvmem: nvmem device to add cells to. + * @info: nvmem cell info to add to the device + * @ncells: number of cells in info + * + * Return: 0 or negative error code on failure. + */ +int nvmem_add_cells(struct nvmem_device *nvmem, + const struct nvmem_cell_info *info, + int ncells) { struct nvmem_cell **cells; - const struct nvmem_cell_info *info = cfg->cells; int i, rval; - cells = kcalloc(cfg->ncells, sizeof(*cells), GFP_KERNEL); + cells = kcalloc(ncells, sizeof(*cells), GFP_KERNEL); if (!cells) return -ENOMEM; - for (i = 0; i < cfg->ncells; i++) { + for (i = 0; i < ncells; i++) { cells[i] = kzalloc(sizeof(**cells), GFP_KERNEL); if (!cells[i]) { rval = -ENOMEM; @@ -380,7 +389,7 @@ static int nvmem_add_cells(struct nvmem_device *nvmem, nvmem_cell_add(cells[i]); } - nvmem->ncells = cfg->ncells; + nvmem->ncells = ncells; /* remove tmp array */ kfree(cells); @@ -393,6 +402,7 @@ static int nvmem_add_cells(struct nvmem_device *nvmem, return rval; } +EXPORT_SYMBOL_GPL(nvmem_add_cells); /* * nvmem_setup_compat() - Create an additional binary entry in @@ -509,7 +519,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) } if (config->cells) - nvmem_add_cells(nvmem, config); + nvmem_add_cells(nvmem, config->cells, config->ncells); return nvmem; diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index f89598bc4e1c..24def6ad09bb 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -77,6 +77,9 @@ struct nvmem_device *devm_nvmem_register(struct device *dev, int devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem); +int nvmem_add_cells(struct nvmem_device *nvmem, + const struct nvmem_cell_info *info, + int ncells); #else static inline struct nvmem_device *nvmem_register(const struct nvmem_config *c) @@ -99,6 +102,14 @@ static inline int devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem) { return nvmem_unregister(nvmem); + +} + +static inline int nvmem_add_cells(struct nvmem_device *nvmem, + const struct nvmem_cell_info *info, + int ncells) +{ + return -ENOSYS; } #endif /* CONFIG_NVMEM */