From patchwork Wed Oct 26 19:59:22 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Dietrich X-Patchwork-Id: 121969 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id D85B21007D2 for ; Thu, 27 Oct 2011 07:00:23 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751893Ab1JZUAX (ORCPT ); Wed, 26 Oct 2011 16:00:23 -0400 Received: from mailout-de.gmx.net ([213.165.64.22]:47982 "HELO mailout-de.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1751347Ab1JZUAX (ORCPT ); Wed, 26 Oct 2011 16:00:23 -0400 Received: (qmail invoked by alias); 26 Oct 2011 20:00:12 -0000 Received: from pD9E5DA49.dip0.t-ipconnect.de (EHLO localhost.localdomain) [217.229.218.73] by mail.gmx.net (mp006) with SMTP; 26 Oct 2011 22:00:12 +0200 X-Authenticated: #9962044 X-Provags-ID: V01U2FsdGVkX18ucecsG6YuIW3Yp/HfQvZvPfwRGAB783WM0qQZQm sy6UBuQQ8+T40L From: Marc Dietrich To: linux-tegra@vger.kernel.org Cc: Olof Johansson , Colin Cross , Marc Dietrich , devel@linuxdriverproject.org, Julian Andres Klode Subject: [PATCH v2 3/3] staging: nvec: add device tree support Date: Wed, 26 Oct 2011 21:59:22 +0200 Message-Id: <48050ec08d248a2a10b4f5faf6cac6b214041ebe.1319658296.git.marvin24@gmx.de> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: References: In-Reply-To: References: X-Y-GMX-Trusted: 0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org This adds device tree support to the nvec driver. By using this method it is no longer necessary to specify platform data through a board file. Cc: devel@linuxdriverproject.org Cc: Julian Andres Klode Signed-off-by: Marc Dietrich --- drivers/staging/nvec/nvec.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 files changed, 37 insertions(+), 2 deletions(-) diff --git a/drivers/staging/nvec/nvec.c b/drivers/staging/nvec/nvec.c index fb0f095..731eeeb 100644 --- a/drivers/staging/nvec/nvec.c +++ b/drivers/staging/nvec/nvec.c @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include #include #include @@ -35,6 +37,8 @@ #include #include +#include + #include #include @@ -718,6 +722,7 @@ static int __devinit tegra_nvec_probe(struct platform_device *pdev) struct resource *res; struct resource *iomem; void __iomem *base; + const unsigned int *prop; nvec = kzalloc(sizeof(struct nvec_chip), GFP_KERNEL); if (nvec == NULL) { @@ -726,8 +731,26 @@ static int __devinit tegra_nvec_probe(struct platform_device *pdev) } platform_set_drvdata(pdev, nvec); nvec->dev = &pdev->dev; - nvec->gpio = pdata->gpio; - nvec->i2c_addr = pdata->i2c_addr; + + if (pdata) { + nvec->gpio = pdata->gpio; + nvec->i2c_addr = pdata->i2c_addr; + } else if (nvec->dev->of_node) { + nvec->gpio = of_get_named_gpio(nvec->dev->of_node, "request-gpios", 0); + if (nvec->gpio < 0) { + dev_err(&pdev->dev, "no gpio specified"); + goto failed; + } + prop = of_get_property(nvec->dev->of_node, "slave-addr", NULL); + if (!prop) { + dev_err(&pdev->dev, "no i2c address specified"); + goto failed; + } + nvec->i2c_addr = be32_to_cpup(prop); + } else { + dev_err(&pdev->dev, "no platform data\n"); + goto failed; + } res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) { @@ -892,6 +915,17 @@ static int tegra_nvec_resume(struct platform_device *pdev) #define tegra_nvec_resume NULL #endif +#if defined(CONFIG_OF) +/* Match table for of_platform binding */ +static const struct of_device_id nvidia_nvec_of_match[] __devinitconst = { + { .compatible = "nvidia,nvec", }, + {}, +}; +MODULE_DEVICE_TABLE(of, nvidia_nvec_of_match); +#else +#define nvidia_nvec_of_match NULL +#endif + static struct platform_driver nvec_device_driver = { .probe = tegra_nvec_probe, .remove = __devexit_p(tegra_nvec_remove), @@ -900,6 +934,7 @@ static struct platform_driver nvec_device_driver = { .driver = { .name = "nvec", .owner = THIS_MODULE, + .of_match_table = nvidia_nvec_of_match, } };