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: 6125811 Return-Path: X-Original-To: patchwork-linux-arm-msm@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 75ABEBF4A6 for ; Mon, 30 Mar 2015 22:00:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 89C9F201FE for ; Mon, 30 Mar 2015 22:00:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A714720211 for ; Mon, 30 Mar 2015 22:00:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752811AbbC3V7w (ORCPT ); Mon, 30 Mar 2015 17:59:52 -0400 Received: from mail-wg0-f43.google.com ([74.125.82.43]:36633 "EHLO mail-wg0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932134AbbC3V6T (ORCPT ); Mon, 30 Mar 2015 17:58:19 -0400 Received: by wgra20 with SMTP id a20so189251788wgr.3 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=RLHo8rO/QMHrf7SphpK2npuBwBGQbW6GKSoPIiY4PYHBXb5ztwGcPAM8vTgUNx6aem xAdImJZ1qR8yqbLTTXHYGDNqH6cP+L47qouSMleMLxj801SdrOR36pTXXK2xFDjppll3 6URmfIc9nKfcnUzPQ3sH31aJN7oHmXgUSLdqwXPOs67NTRCTMDrZyI2NKf5qJjUa7P/G hHNH6Zm12gY4E4122F24viHKL+uuhBlsOcyuRcqZiCNPY4CjYVRUa75vBNGHDzS0I5WI eTXV9G5Ggrg2dF8mngFXj/YwEx7pqpDVRRayJADYXV05SI7aOlNNuVYoHsJtChWFZjCI E3sg== X-Gm-Message-State: ALoCoQmQ112s6+061F7Q4wrKaOX/JnQovaXavbSfRdzrwPO/17c9co65In1qO9IOXd3WQuweliHN 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 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 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> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 */