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: 46563 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id DB420218BE for ; Mon, 30 Mar 2015 22:00:01 +0000 (UTC) Received: by lbcgc5 with SMTP id gc5sf3124188lbc.1 for ; Mon, 30 Mar 2015 15:00:00 -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=4Fbd5SACdddWHpu0CG1my1bVywOC4gIADGCKfYHdGGc=; b=CwN7X6K0+4TM6+cIw/Hggz1SAejhqYzCJn5u+wvUJ8Q31n3jInu6MKGipH0uQsaHXI l0A0+sIkur2Li3GdW67VjWzZaRpqGPXuHEW8FHHbTZFCZt+5nz6MFpT6j03nOUX1PgAi 8UWLq+HFYTNQ/oBtBOZPNfgYZ7G+cW2RsvjCwQZn24bFsVM9db1YoQ6wgDHEcWHT9wlc er60pDFW9vOLtQyahl1wqWeoJcoxb2faGboVi9wd2rjjuvHrYA1bzxJ/N44O/8NWrrAA TfCZdz+Ke09dOoOqvdZXrg5VcdbAiMC3ZUWkOZcLGdGaw/16WEazYQaD03N62Lca8bT3 RQ2Q== X-Gm-Message-State: ALoCoQlBFICF7HdcwwfSHXc75WB9SF+9Zx9rkZEtW/qGknw27RXvZnwPUJdbktF9qjLo3Fw7i9BX X-Received: by 10.194.95.67 with SMTP id di3mr9080174wjb.0.1427752800882; Mon, 30 Mar 2015 15:00:00 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.28.67 with SMTP id z3ls179215lag.3.gmail; Mon, 30 Mar 2015 15:00:00 -0700 (PDT) X-Received: by 10.112.89.71 with SMTP id bm7mr28534627lbb.20.1427752800629; Mon, 30 Mar 2015 15:00:00 -0700 (PDT) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com. [209.85.217.179]) by mx.google.com with ESMTPS id rh2si7874606lbb.141.2015.03.30.15.00.00 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Mar 2015 15:00:00 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.179 as permitted sender) client-ip=209.85.217.179; Received: by lbcmq2 with SMTP id mq2so104946337lbc.0 for ; Mon, 30 Mar 2015 15:00:00 -0700 (PDT) X-Received: by 10.152.116.11 with SMTP id js11mr28460992lab.106.1427752800494; Mon, 30 Mar 2015 15:00:00 -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.57.201 with SMTP id k9csp1410923lbq; Mon, 30 Mar 2015 14:59:59 -0700 (PDT) X-Received: by 10.67.22.201 with SMTP id hu9mr30973561pad.121.1427752797947; Mon, 30 Mar 2015 14:59:57 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e2si1235030pdb.44.2015.03.30.14.59.56; Mon, 30 Mar 2015 14:59:57 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932215AbbC3V7w (ORCPT + 27 others); Mon, 30 Mar 2015 17:59:52 -0400 Received: from mail-wg0-f48.google.com ([74.125.82.48]:34769 "EHLO mail-wg0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932140AbbC3V6T (ORCPT ); Mon, 30 Mar 2015 17:58:19 -0400 Received: by wgbdm7 with SMTP id dm7so83769969wgb.1 for ; Mon, 30 Mar 2015 14:58:17 -0700 (PDT) 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-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.217.179 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 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 */