From patchwork Thu May 21 16:44:25 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 48869 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8C05D21411 for ; Thu, 21 May 2015 16:46:56 +0000 (UTC) Received: by wixv7 with SMTP id v7sf5611515wix.0 for ; Thu, 21 May 2015 09:46:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=6lqUXDlYbtliVnlWLHqXoUyaNmHrpk9KcrpPAlruoVw=; b=cwdFEEMybM4uyMr58dAPMwKS38EB6mT0Z3nWuR7FjOPlLktthp2E/9bd9guRsl1+2a VGTCIEzSW+6hROHaVFB2Nr+fuUniimyPxtCKh7EMPBo0La2LnYJpktn1FFgbzHDGLk5t GfHSiCpk97xcjC/KP4nJPZBa/lRbByutOwmEe2Uihs/iekO9VO95IzNdDnZ3MN0WjWWL 4NHbj/I3GPY+g94POJoez/Dpe4XVPkrkW0YD1urfixqqHlhwnLti5bZNDfkSpLRA11Vc QlL92HCL9IubIHY1sh1ZH+EL0YZrozdy5gbvpN3APW75fC8trgi0RbXiZNSW8gzeTDlM cG9w== X-Gm-Message-State: ALoCoQnDexNIYabI+F6gtZNeyGcUU6YXx8RDBPdYS4kFennNlzAoBqk/vt7Kpn3KjXpJgzIcm9VC X-Received: by 10.112.26.5 with SMTP id h5mr3487597lbg.4.1432226815751; Thu, 21 May 2015 09:46:55 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.101 with SMTP id r5ls345350lar.78.gmail; Thu, 21 May 2015 09:46:55 -0700 (PDT) X-Received: by 10.152.3.130 with SMTP id c2mr3062013lac.81.1432226815563; Thu, 21 May 2015 09:46:55 -0700 (PDT) Received: from mail-la0-f45.google.com (mail-la0-f45.google.com. [209.85.215.45]) by mx.google.com with ESMTPS id jj4si13582092lbb.174.2015.05.21.09.46.55 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 May 2015 09:46:55 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) client-ip=209.85.215.45; Received: by lagr1 with SMTP id r1so106880253lag.0 for ; Thu, 21 May 2015 09:46:55 -0700 (PDT) X-Received: by 10.152.6.69 with SMTP id y5mr2973705lay.72.1432226815129; Thu, 21 May 2015 09:46:55 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp724419lbb; Thu, 21 May 2015 09:46:53 -0700 (PDT) X-Received: by 10.68.112.195 with SMTP id is3mr7380672pbb.92.1432226813152; Thu, 21 May 2015 09:46:53 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id pe8si7072535pac.157.2015.05.21.09.46.23; Thu, 21 May 2015 09:46:53 -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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756866AbbEUQog (ORCPT + 28 others); Thu, 21 May 2015 12:44:36 -0400 Received: from mail-wi0-f176.google.com ([209.85.212.176]:34221 "EHLO mail-wi0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756865AbbEUQoc (ORCPT ); Thu, 21 May 2015 12:44:32 -0400 Received: by wicmc15 with SMTP id mc15so18610725wic.1 for ; Thu, 21 May 2015 09:44:30 -0700 (PDT) X-Received: by 10.180.106.70 with SMTP id gs6mr52371958wib.36.1432226670638; Thu, 21 May 2015 09:44:30 -0700 (PDT) Received: from srini-ThinkPad-X1-Carbon-2nd.dlink.com (host-2-96-95-164.as13285.net. [2.96.95.164]) by mx.google.com with ESMTPSA id fw3sm3675901wic.13.2015.05.21.09.44.27 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 21 May 2015 09:44:29 -0700 (PDT) From: Srinivas Kandagatla To: linux-arm-kernel@lists.infradead.org Cc: Maxime Ripard , Rob Herring , Kumar Gala , Mark Brown , s.hauer@pengutronix.de, Greg Kroah-Hartman , linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-msm@vger.kernel.org, arnd@arndb.de, sboyd@codeaurora.org, Srinivas Kandagatla , pantelis.antoniou@konsulko.com, mporter@konsulko.com Subject: [PATCH v5 07/11] nvmem: Add simple nvmem-mmio consumer helper functions. Date: Thu, 21 May 2015 17:44:25 +0100 Message-Id: <1432226665-8994-1-git-send-email-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1432226535-8640-1-git-send-email-srinivas.kandagatla@linaro.org> References: <1432226535-8640-1-git-send-email-srinivas.kandagatla@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: srinivas.kandagatla@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This patch adds probe and remove helper functions for nvmems which are mmio based, With these helper function new nvmem consumer drivers need very little code add its driver. This code is currently used for qfprom and sunxi-sid nvmem consumer drivers. Signed-off-by: Srinivas Kandagatla --- drivers/nvmem/Makefile | 1 + drivers/nvmem/nvmem-mmio.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/nvmem/nvmem-mmio.h | 41 +++++++++++++++++++++++++++ 3 files changed, 111 insertions(+) create mode 100644 drivers/nvmem/nvmem-mmio.c create mode 100644 drivers/nvmem/nvmem-mmio.h diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile index 6df2c69..f694cfc 100644 --- a/drivers/nvmem/Makefile +++ b/drivers/nvmem/Makefile @@ -4,3 +4,4 @@ obj-$(CONFIG_NVMEM) += nvmem_core.o nvmem_core-y := core.o +nvmem_core-y += nvmem-mmio.o diff --git a/drivers/nvmem/nvmem-mmio.c b/drivers/nvmem/nvmem-mmio.c new file mode 100644 index 0000000..0d8131f --- /dev/null +++ b/drivers/nvmem/nvmem-mmio.c @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2015 Srinivas Kandagatla + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include "nvmem-mmio.h" + +int nvmem_mmio_remove(struct platform_device *pdev) +{ + struct nvmem_device *nvmem = platform_get_drvdata(pdev); + + return nvmem_unregister(nvmem); +} +EXPORT_SYMBOL_GPL(nvmem_mmio_remove); + +int nvmem_mmio_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct resource *res; + const struct nvmem_mmio_data *data; + struct nvmem_device *nvmem; + struct regmap *regmap; + const struct of_device_id *match; + void __iomem *base; + + if (!dev || !dev->driver) + return -ENODEV; + + match = of_match_device(dev->driver->of_match_table, dev); + if (!match || !match->data) + return -EINVAL; + + data = match->data; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + base = devm_ioremap_resource(dev, res); + if (IS_ERR(base)) + return PTR_ERR(base); + + data->regmap_config->max_register = resource_size(res) - 1; + + regmap = devm_regmap_init_mmio(dev, base, data->regmap_config); + if (IS_ERR(regmap)) { + dev_err(dev, "regmap init failed\n"); + return PTR_ERR(regmap); + } + data->nvmem_config->dev = dev; + nvmem = nvmem_register(data->nvmem_config); + if (IS_ERR(nvmem)) + return PTR_ERR(nvmem); + + platform_set_drvdata(pdev, nvmem); + + return 0; +} +EXPORT_SYMBOL_GPL(nvmem_mmio_probe); diff --git a/drivers/nvmem/nvmem-mmio.h b/drivers/nvmem/nvmem-mmio.h new file mode 100644 index 0000000..a2ad4e5 --- /dev/null +++ b/drivers/nvmem/nvmem-mmio.h @@ -0,0 +1,41 @@ +/* + * MMIO based nvmem providers. + * + * Copyright (C) 2015 Srinivas Kandagatla + * + * This file is licensed under the terms of the GNU General Public + * License version 2. This program is licensed "as is" without any + * warranty of any kind, whether express or implied. + */ + +#ifndef _LINUX_NVMEM_MMIO_H +#define _LINUX_NVMEM_MMIO_H + +#include +#include +#include + +struct nvmem_mmio_data { + struct regmap_config *regmap_config; + struct nvmem_config *nvmem_config; +}; + +#if IS_ENABLED(CONFIG_NVMEM) + +int nvmem_mmio_probe(struct platform_device *pdev); +int nvmem_mmio_remove(struct platform_device *pdev); + +#else + +static inline int nvmem_mmio_probe(struct platform_device *pdev) +{ + return -ENOSYS; +} + +static inline int nvmem_mmio_remove(struct platform_device *pdev) +{ + return -ENOSYS; +} +#endif + +#endif /* ifndef _LINUX_NVMEM_MMIO_H */