From patchwork Mon Mar 30 21:58:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 6125921 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 02832BF4A6 for ; Mon, 30 Mar 2015 22:05:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CAE5D2043C for ; Mon, 30 Mar 2015 22:05:57 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AFFC5203B0 for ; Mon, 30 Mar 2015 22:05:56 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ychm6-0003ih-BR; Mon, 30 Mar 2015 22:03:14 +0000 Received: from mail-wg0-f47.google.com ([74.125.82.47]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ychhd-0000JW-6q for linux-arm-kernel@lists.infradead.org; Mon, 30 Mar 2015 21:58:38 +0000 Received: by wgdm6 with SMTP id m6so190166717wgd.2 for ; Mon, 30 Mar 2015 14:58:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+BqA1Ij/Q1adjXpByVgT7OBlVmfItt/WwZDj4nhZsAE=; b=QOE19fNKXLaFivx3YfixIiY2vpz8D5yUugJlMdYAC6xW5Jcjd3lntnu4PwGVlHbF3e Da0WBT9Sc8cKeBu41tSVzpOsjLDtFM1/mMXsfmR1YWS9chErGWdQHGMkooKvF5R8ZmhT f7JOW8vpoCfAkLcP07Z++amH6IKWyqeAvv8ZgMX/CYecCqg95z6/lmWK3ozIkK+LW0BD 2CuVe3S1brC9aLZcZD+LSMzPOO9ibYR92kHuXLjVo0Hrnb5CozVD+PlWlRRGnyU7r+A1 drtiJl4mnRJcOFnDebLcuHpBVTgC2N9iLMxJTfVsC/q1TN3qhnGrzFH2HzROPuwCmgJX OjMQ== X-Gm-Message-State: ALoCoQmuYLMz+TVdM0BbhY1OahQoVNDDRRFv0EkhvCnsJhegGUIBCP3bGuiUhUlXkVObkBt+J3OI X-Received: by 10.194.60.203 with SMTP id j11mr69195579wjr.5.1427752697631; Mon, 30 Mar 2015 14:58:17 -0700 (PDT) Received: from srini-ThinkPad-X1-Carbon-2nd.dlink.com (host-78-145-247-151.as13285.net. [78.145.247.151]) by mx.google.com with ESMTPSA id dj4sm17537211wjc.13.2015.03.30.14.58.15 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 30 Mar 2015 14:58:16 -0700 (PDT) From: Srinivas Kandagatla To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 06/10] eeprom: Add simple eeprom-mmio consumer helper functions. Date: Mon, 30 Mar 2015 22:58:13 +0100 Message-Id: <1427752693-17303-1-git-send-email-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1427752492-17039-1-git-send-email-srinivas.kandagatla@linaro.org> References: <1427752492-17039-1-git-send-email-srinivas.kandagatla@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150330_145837_445014_59029018 X-CRM114-Status: GOOD ( 15.01 ) X-Spam-Score: -0.7 (/) Cc: devicetree@vger.kernel.org, arnd@arndb.de, Greg Kroah-Hartman , s.hauer@pengutronix.de, sboyd@codeaurora.org, linux-kernel@vger.kernel.org, Rob Herring , Srinivas Kandagatla , Mark Brown , Kumar Gala , Maxime Ripard , linux-api@vger.kernel.org, linux-arm-msm@vger.kernel.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds probe and remove helper functions for eeproms which are mmio based, With these helper function new eeprom consumer drivers need very little code add its driver. This code is currently used for qfprom and sunxi-sid eeprom consumer drivers. Signed-off-by: Srinivas Kandagatla --- drivers/eeprom/Makefile | 1 + drivers/eeprom/eeprom-mmio.c | 69 ++++++++++++++++++++++++++++++++++++++++++++ drivers/eeprom/eeprom-mmio.h | 41 ++++++++++++++++++++++++++ 3 files changed, 111 insertions(+) create mode 100644 drivers/eeprom/eeprom-mmio.c create mode 100644 drivers/eeprom/eeprom-mmio.h diff --git a/drivers/eeprom/Makefile b/drivers/eeprom/Makefile index 51a727f..6812bbe 100644 --- a/drivers/eeprom/Makefile +++ b/drivers/eeprom/Makefile @@ -4,3 +4,4 @@ obj-$(CONFIG_EEPROM) += eeprom_core.o eeprom_core-y := core.o +eeprom_core-y += eeprom-mmio.o diff --git a/drivers/eeprom/eeprom-mmio.c b/drivers/eeprom/eeprom-mmio.c new file mode 100644 index 0000000..55b8913 --- /dev/null +++ b/drivers/eeprom/eeprom-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 "eeprom-mmio.h" + +int eeprom_mmio_remove(struct platform_device *pdev) +{ + struct eeprom_device *eeprom = platform_get_drvdata(pdev); + + return eeprom_unregister(eeprom); +} +EXPORT_SYMBOL_GPL(eeprom_mmio_remove); + +int eeprom_mmio_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct resource *res; + const struct eeprom_mmio_data *data; + struct eeprom_device *eeprom; + 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->eeprom_config->dev = dev; + eeprom = eeprom_register(data->eeprom_config); + if (IS_ERR(eeprom)) + return PTR_ERR(eeprom); + + platform_set_drvdata(pdev, eeprom); + + return 0; +} +EXPORT_SYMBOL_GPL(eeprom_mmio_probe); diff --git a/drivers/eeprom/eeprom-mmio.h b/drivers/eeprom/eeprom-mmio.h new file mode 100644 index 0000000..e58bcc8 --- /dev/null +++ b/drivers/eeprom/eeprom-mmio.h @@ -0,0 +1,41 @@ +/* + * MMIO based EEPROM 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_EEPROM_MMIO_H +#define _LINUX_EEPROM_MMIO_H + +#include +#include +#include + +struct eeprom_mmio_data { + struct regmap_config *regmap_config; + struct eeprom_config *eeprom_config; +}; + +#if IS_ENABLED(CONFIG_EEPROM) + +int eeprom_mmio_probe(struct platform_device *pdev); +int eeprom_mmio_remove(struct platform_device *pdev); + +#else + +static inline int eeprom_mmio_probe(struct platform_device *pdev) +{ + return -ENOSYS; +} + +static inline int eeprom_mmio_remove(struct platform_device *pdev) +{ + return -ENOSYS; +} +#endif + +#endif /* ifndef _LINUX_EEPROM_MMIO_H */