From patchwork Tue May 31 11:43:05 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Jander X-Patchwork-Id: 98013 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 3659DB6F72 for ; Tue, 31 May 2011 21:43:49 +1000 (EST) Received: by wyb35 with SMTP id 35sf11868980wyb.11 for ; Tue, 31 May 2011 04:43:45 -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: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=6yci+8cyySEH7IAKoGlVe1F2oxPlf5iAEX7+/qE95R0=; b=aE7vGELvZMNm8xMlp8l8fcrshxXSHXqU6OTjFJetGzvl8OCJtvveljqMV6cZ2wnh+6 dl0V2Y8fHkUzHtGVl/KBZV7FVItUooavobiqva921wqAqfQWBzA0MUwsDydqt1m3vjE/ B1LA3A6oMh81cYix2iUWXvjzY5mQsSWrnKVDg= 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: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=dpplAjuHG2HdnI2NKdPfOsQXWTameDYTXcPjShTgMRHFjbQ+J968/hda//KuOQ+0ev oeHa5UeLPtILViROyquHOI4s7CQLRAiw4eVNenkUzwPBhICUG0N8ovOWx/2GZ7dWmPE+ Mr+2wxJ2tWE1xH+DHcHRYuy6DvK7NpsbDlumI= Received: by 10.216.220.149 with SMTP id o21mr2397231wep.1.1306842224379; Tue, 31 May 2011 04:43:44 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: rtc-linux@googlegroups.com Received: by 10.14.41.227 with SMTP id h75ls654541eeb.3.gmail; Tue, 31 May 2011 04:43:43 -0700 (PDT) Received: by 10.14.11.83 with SMTP id 59mr1498133eew.13.1306842223349; Tue, 31 May 2011 04:43:43 -0700 (PDT) Received: by 10.14.11.83 with SMTP id 59mr1498132eew.13.1306842223332; Tue, 31 May 2011 04:43:43 -0700 (PDT) Received: from protonic.xs4all.nl (protonic.xs4all.nl [213.84.116.84]) by gmr-mx.google.com with ESMTP id u44si3872790eef.0.2011.05.31.04.43.42; Tue, 31 May 2011 04:43:42 -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 447D329EBB; Tue, 31 May 2011 13:41:32 +0200 (CEST) From: David Jander To: raph@8d.com Cc: a.zummo@towertech.it, rtc-linux@googlegroups.com, David Jander Subject: [rtc-linux] [PATCH v2] RTC: rtc-v3020.c: Added support for device-tree platform data Date: Tue, 31 May 2011 13:43:05 +0200 Message-Id: <1306842185-9725-1-git-send-email-david@protonic.nl> X-Mailer: git-send-email 1.7.4.1 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 | 32 +++++++++ drivers/rtc/rtc-v3020.c | 74 ++++++++++++++++++++ 2 files changed, 106 insertions(+), 0 deletions(-) diff --git a/Documentation/devicetree/bindings/rtc/rtc-v3020.txt b/Documentation/devicetree/bindings/rtc/rtc-v3020.txt new file mode 100644 index 0000000..8c470e1 --- /dev/null +++ b/Documentation/devicetree/bindings/rtc/rtc-v3020.txt @@ -0,0 +1,32 @@ + EM Marin V3020 compatible RTC +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Required properties: + - compatible: "em,v3020", "v3020" + - reg: Memory address if mmio mode is used, otherwise not used. + +Optional properties: + - "use_gpio": integer. If defined and not "0", use gpio access mode. + - "leftshift": integer. Contains the leftshift parameter of + struct v3020_platform_data. + - "gpio_cs", "gpio_wr", "gpio_rd" and "gpio_io": integers, representing + the GPIO pin numbers to use in struct v3020_platform_data if gpio access + mode is used. + +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..78c0394 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,9 @@ #include #include #include +#ifdef CONFIG_OF +#include +#endif #include @@ -65,6 +71,8 @@ struct v3020 { struct v3020_chip_ops *ops; struct rtc_device *rtc; + + int dyn_pdata; }; @@ -301,6 +309,50 @@ static const struct rtc_class_ops v3020_rtc_ops = { .set_time = v3020_set_time, }; +#ifdef CONFIG_OF +static int get_of_pdata(struct v3020_platform_data **pdata, struct platform_device *pdev) +{ + const unsigned int *val; + + *pdata = kzalloc(sizeof **pdata, GFP_KERNEL); + if (!*pdata) + return -ENOMEM; + + pdev->dev.platform_data = *pdata; + + val = of_get_property(pdev->dev.of_node, "use_gpio", NULL); + if (val) + (*pdata)->use_gpio = *val; + + val = of_get_property(pdev->dev.of_node, "leftshift", NULL); + if (val) + (*pdata)->leftshift = *val; + + val = of_get_property(pdev->dev.of_node, "gpio_cs", NULL); + if (val) + (*pdata)->gpio_cs = *val; + + val = of_get_property(pdev->dev.of_node, "gpio_wr", NULL); + if (val) + (*pdata)->gpio_wr = *val; + + val = of_get_property(pdev->dev.of_node, "gpio_rd", NULL); + if (val) + (*pdata)->gpio_rd = *val; + + val = of_get_property(pdev->dev.of_node, "gpio_io", NULL); + if (val) + (*pdata)->gpio_io = *val; + + return 0; +} +#else +static int get_of_pdata(struct v3020_platform_data *pdata, struct v3020 *chip) +{ + return -ENODEV; +} +#endif + static int rtc_probe(struct platform_device *pdev) { struct v3020_platform_data *pdata = pdev->dev.platform_data; @@ -313,6 +365,13 @@ static int rtc_probe(struct platform_device *pdev) if (!chip) return -ENOMEM; + if (!pdata && pdev->dev.of_node) { + retval = get_of_pdata(&pdata, pdev); + if (retval) + goto err_chip; + chip->dyn_pdata = 1; + } + if (pdata->use_gpio) chip->ops = &v3020_gpio_ops; else @@ -365,6 +424,8 @@ static int rtc_probe(struct platform_device *pdev) err_io: chip->ops->unmap_io(chip); err_chip: + if (chip->dyn_pdata) + kfree(pdev->dev.platform_data); kfree(chip); return retval; @@ -379,17 +440,30 @@ static int rtc_remove(struct platform_device *dev) rtc_device_unregister(rtc); chip->ops->unmap_io(chip); + if (chip->dyn_pdata) + kfree(dev->dev.platform_data); kfree(chip); 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 }, };