From patchwork Thu Jun 9 18:39:29 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Jander X-Patchwork-Id: 99790 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-wy0-f184.google.com (mail-wy0-f184.google.com [74.125.82.184]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (verified OK)) by ozlabs.org (Postfix) with ESMTPS id 4737AB6F99 for ; Fri, 10 Jun 2011 04:39:42 +1000 (EST) Received: by wyb35 with SMTP id 35sf3692839wyb.11 for ; Thu, 09 Jun 2011 11:39:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=domainkey-signature:mime-version:x-beenthere:received-spf:from:to :cc:subject:date:message-id:x-mailer:in-reply-to:references :x-original-sender:x-original-authentication-results:reply-to :precedence:mailing-list:list-id:x-google-group-id:list-post :list-help:list-archive:sender:list-subscribe:list-unsubscribe :content-type; bh=WHFoY9L2xdypt1ouvMvRjG6CS9IB0keT0fXc3TjdMKU=; b=TF1BHWiW5HzFRgBnM5fvNyv3Q2QH8Mz8KAmzkpvMYvWOrkr7C7Sf3tMQ/v1thRaHOd 0ZIXCx8Roupkuk6NdGiN8RPgXJ0E7QSDoqgzVd0CvQvRmzHUYaHUA8rjaLjBk50NO3ws Km7na0bvnaqorzCTIsuYjq7upVpGG5fH7ov/4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlegroups.com; s=beta; h=mime-version:x-beenthere:received-spf:from:to:cc:subject:date :message-id:x-mailer:in-reply-to:references:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:x-google-group-id:list-post:list-help:list-archive:sender :list-subscribe:list-unsubscribe:content-type; b=lDtIED0j5XZVre9zOY6w//MNLBguSv6CcgHKomCvomxEivE1Rsx1uqpK8630HIiX3F qYS4tVkUgdZeltCWMfWJXMNPXHmmDB3Bho+wzw15zgVyt5AwpP6JGb/9jWNH2MblB86s N68N9e3Wpw8mCJseAE2juHg2uBTfOTaNdBvXQ= Received: by 10.216.78.133 with SMTP id g5mr2822678wee.19.1307644776757; Thu, 09 Jun 2011 11:39:36 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: rtc-linux@googlegroups.com Received: by 10.14.14.136 with SMTP id d8ls123097eed.6.gmail; Thu, 09 Jun 2011 11:39:35 -0700 (PDT) Received: by 10.14.189.9 with SMTP id b9mr265031een.10.1307644775661; Thu, 09 Jun 2011 11:39:35 -0700 (PDT) Received: by 10.14.189.9 with SMTP id b9mr265030een.10.1307644775595; Thu, 09 Jun 2011 11:39:35 -0700 (PDT) Received: from protonic.xs4all.nl (protonic.xs4all.nl [213.84.116.84]) by gmr-mx.google.com with ESMTP id n13si1280518eea.3.2011.06.09.11.39.34; Thu, 09 Jun 2011 11:39:34 -0700 (PDT) Received-SPF: neutral (google.com: 213.84.116.84 is neither permitted nor denied by best guess record for domain of david@protonic.nl) client-ip=213.84.116.84; Received: from archvile.prtnl (archvile.prtnl [192.168.1.153]) by protonic.xs4all.nl (Postfix) with ESMTP id 7CC9D29EBA; Thu, 9 Jun 2011 20:37:23 +0200 (CEST) From: David Jander To: raph@8d.com Cc: a.zummo@towertech.it, rtc-linux@googlegroups.com, david@protonic.nl Subject: [rtc-linux] [PATCH v3] RTC: rtc-v3020.c: Added support for device-tree binding Date: Thu, 9 Jun 2011 20:39:29 +0200 Message-Id: <1307644769-25598-1-git-send-email-david@protonic.nl> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1306842185-9725-1-git-send-email-david@protonic.nl> References: <1306842185-9725-1-git-send-email-david@protonic.nl> X-Original-Sender: david@protonic.nl X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 213.84.116.84 is neither permitted nor denied by best guess record for domain of david@protonic.nl) smtp.mail=david@protonic.nl Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: X-Google-Group-Id: 712029733259 List-Post: , List-Help: , List-Archive: Sender: rtc-linux@googlegroups.com List-Subscribe: , List-Unsubscribe: , Added support for fetching platform data from OF device-tree. Signed-off-by: David Jander --- .../devicetree/bindings/rtc/rtc-v3020.txt | 31 +++++++++++ drivers/rtc/rtc-v3020.c | 57 ++++++++++++++++++++ 2 files changed, 88 insertions(+), 0 deletions(-) create mode 100644 Documentation/devicetree/bindings/rtc/rtc-v3020.txt diff --git a/Documentation/devicetree/bindings/rtc/rtc-v3020.txt b/Documentation/devicetree/bindings/rtc/rtc-v3020.txt new file mode 100644 index 0000000..1799a84 --- /dev/null +++ b/Documentation/devicetree/bindings/rtc/rtc-v3020.txt @@ -0,0 +1,31 @@ + EM Marin V3020 compatible RTC +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Required properties: + - compatible: "em,v3020", "v3020" + - reg: Memory address if mmio mode is used, otherwise not used. + +Optional properties: + - "leftshift": integer. Contains the leftshift parameter of + struct v3020_platform_data. + - "gpios": gpios property. Array of 4 OF gpio specifiers, which if specified + select gpio mode. The four gpios are gpio_cs, gpio_wr, gpio_rd and + gpio_io in this order. See Documentation/devicetree/bindings/gpio/gpio.txt + +Example for MMIO on MPC5121 localbus: + + localbus@80000020 { + compatible = "fsl,mpc5121-localbus"; + #address-cells = <2>; + #size-cells = <1>; + reg = <0x80000020 0x40>; + ranges = <0x0 0x0 0xfe000000 0x02000000 /* Flash */ + 0x1 0x0 0xf8000000 0x00000004>; /* V3020 */ + ... + v3020@1,0 { + compatible = "em,v3020", "v3020"; + reg = <1 0 4>; + leftshift = <24>; + }; + ... + diff --git a/drivers/rtc/rtc-v3020.c b/drivers/rtc/rtc-v3020.c index f71c3ce..b582448 100644 --- a/drivers/rtc/rtc-v3020.c +++ b/drivers/rtc/rtc-v3020.c @@ -11,6 +11,9 @@ * * Changelog: * + * 31-May-2011: David Jander + * - Added OF support + * * 10-May-2006: Raphael Assenat * - Converted to platform driver * - Use the generic rtc class @@ -29,6 +32,8 @@ #include #include #include +#include +#include #include @@ -301,9 +306,45 @@ static const struct rtc_class_ops v3020_rtc_ops = { .set_time = v3020_set_time, }; +#ifdef CONFIG_OF +static void get_of_pdata(struct v3020_platform_data *pdata, + struct platform_device *pdev) +{ + const unsigned int *val; + unsigned int gpio; + + memset(pdata, 0, sizeof *pdata); + if (of_find_property(pdev->dev.of_node, "gpios", NULL) != NULL) { + pdata->use_gpio = 1; + gpio = of_get_gpio_flags(pdev->dev.of_node, 0, NULL); + if (gpio >= 0) + pdata->gpio_cs = gpio; + gpio = of_get_gpio_flags(pdev->dev.of_node, 1, NULL); + if (gpio >= 0) + pdata->gpio_wr = gpio; + gpio = of_get_gpio_flags(pdev->dev.of_node, 2, NULL); + if (gpio >= 0) + pdata->gpio_rd = gpio; + gpio = of_get_gpio_flags(pdev->dev.of_node, 3, NULL); + if (gpio >= 0) + pdata->gpio_io = gpio; + } else { + val = of_get_property(pdev->dev.of_node, "leftshift", NULL); + if (val) + pdata->leftshift = *val; + } +} +#else +static void get_of_pdata(struct v3020_platform_data *pdata, + struct platform_device *pdev) +{ +} +#endif + static int rtc_probe(struct platform_device *pdev) { struct v3020_platform_data *pdata = pdev->dev.platform_data; + struct v3020_platform_data alt_pdata; struct v3020 *chip; int retval = -EBUSY; int i; @@ -313,6 +354,11 @@ static int rtc_probe(struct platform_device *pdev) if (!chip) return -ENOMEM; + if (!pdata && pdev->dev.of_node) { + get_of_pdata(&alt_pdata, pdev); + pdata = &alt_pdata; + } + if (pdata->use_gpio) chip->ops = &v3020_gpio_ops; else @@ -384,12 +430,23 @@ static int rtc_remove(struct platform_device *dev) return 0; } +#ifdef CONFIG_OF +const struct of_device_id v3020_of_match[] = { + { + .compatible = "v3020", + }, +}; +#endif + static struct platform_driver rtc_device_driver = { .probe = rtc_probe, .remove = rtc_remove, .driver = { .name = "v3020", .owner = THIS_MODULE, +#ifdef CONFIG_OF + .of_match_table = v3020_of_match, +#endif }, };