From patchwork Wed Apr 16 17:17:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Yanovich X-Patchwork-Id: 4003231 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3CD769F3FF for ; Wed, 16 Apr 2014 17:21:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 54C2B2027D for ; Wed, 16 Apr 2014 17:21:44 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 66B3E20375 for ; Wed, 16 Apr 2014 17:21:43 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WaTUU-0006fq-Qx; Wed, 16 Apr 2014 17:19:18 +0000 Received: from mail-lb0-f177.google.com ([209.85.217.177]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WaTUL-0005sQ-6F for linux-arm-kernel@lists.infradead.org; Wed, 16 Apr 2014 17:19:10 +0000 Received: by mail-lb0-f177.google.com with SMTP id z11so8186156lbi.8 for ; Wed, 16 Apr 2014 10:18:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YnIhINp9H2YBJ3R+jZfiklYORNuE2vkitPqHmgkgSQw=; b=d5Z2CWER5kkzalQufUxX6Ks5DwPt7nwwVr/BwKiEIy6Hm4sRf2q3RZab2CMQ7hcFLq UsTFd8CS2Srb6GjOf3HAWtpbb9KYKuEH2/G/7NL+tPyHL1oaKgPShzNmJLSOpPg3NVx7 bMBOsQmcaX4qBM4MkjmrYwEoHBp+XgFLPdpLfg0t29uzSlOy5QFMn7UvvupVKWXviht+ iA8DyPLIiNaevkMUgfyO7NCYayNXNJEQF1UntMCfogiP//9V3VxY1XjcKHKNZ2/6fqrg t+2GLSGDrACCYlp9zBDkk49eQE6WB6ywpsR/4rDGaOVihTh+7AkH5jgZNnfv/A2MlRD3 OFDg== X-Received: by 10.152.239.137 with SMTP id vs9mr1832646lac.59.1397668721362; Wed, 16 Apr 2014 10:18:41 -0700 (PDT) Received: from host5.omatika.ru (0893675324.static.corbina.ru. [95.31.1.192]) by mx.google.com with ESMTPSA id q4sm21186297lbh.20.2014.04.16.10.18.39 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 16 Apr 2014 10:18:40 -0700 (PDT) From: Sergei Ianovich To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 09/21] rtc: support DS1302 RTC on ICP DAS LP-8x4x Date: Wed, 16 Apr 2014 21:17:14 +0400 Message-Id: <1397668667-27328-3-git-send-email-ynvich@gmail.com> X-Mailer: git-send-email 1.9.2 In-Reply-To: <1397668667-27328-1-git-send-email-ynvich@gmail.com> References: <1397668411-27162-7-git-send-email-ynvich@gmail.com> <1397668667-27328-1-git-send-email-ynvich@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140416_101909_627306_C57C6411 X-CRM114-Status: GOOD ( 19.67 ) X-Spam-Score: -0.8 (/) Cc: Mark Rutland , Alessandro Zummo , Heikki Krogerus , Russell King , rtc-linux@googlegroups.com, Pawel Moll , Ian Campbell , Randy Dunlap , "open list:DOCUMENTATION" , Sergei Ianovich , "open list:OPEN FIRMWARE AND..." , Rob Herring , Kumar Gala , Grant Likely X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 Signed-off-by: Sergei Ianovich --- v3..v4 * move DTS bindings to a different patch (8/21) v2..v3 * use usleep_range instead of custom nsleep * number change (07/16 -> 09/21) v0..v2 * use device tree * use devm helpers where possible .../devicetree/bindings/rtc/rtc-ds1302.txt | 14 +++ arch/arm/configs/lp8x4x_defconfig | 1 + drivers/rtc/Kconfig | 2 +- drivers/rtc/rtc-ds1302.c | 100 ++++++++++++++++++++- 4 files changed, 114 insertions(+), 3 deletions(-) create mode 100644 Documentation/devicetree/bindings/rtc/rtc-ds1302.txt diff --git a/Documentation/devicetree/bindings/rtc/rtc-ds1302.txt b/Documentation/devicetree/bindings/rtc/rtc-ds1302.txt new file mode 100644 index 0000000..810613b --- /dev/null +++ b/Documentation/devicetree/bindings/rtc/rtc-ds1302.txt @@ -0,0 +1,14 @@ +* Dallas Semiconductor DS-1302 RTC + +Simple device which could be used to store date/time between reboots. + +Required properties: +- compatible : Should be "dallas,rtc-ds1302" +- reg : Should be address and size of IO memory region + +Examples: + +rtc@40900000 { + compatible = "dallas,rtc-ds1302"; + reg = <0x1700901c 0x1>; +}; diff --git a/arch/arm/configs/lp8x4x_defconfig b/arch/arm/configs/lp8x4x_defconfig index 9f1efb6..d60e37a 100644 --- a/arch/arm/configs/lp8x4x_defconfig +++ b/arch/arm/configs/lp8x4x_defconfig @@ -141,6 +141,7 @@ CONFIG_LEDS_GPIO=y CONFIG_LEDS_TRIGGERS=y CONFIG_LEDS_TRIGGER_HEARTBEAT=y CONFIG_RTC_CLASS=y +CONFIG_RTC_DRV_DS1302=y CONFIG_RTC_DRV_PXA=m # CONFIG_IOMMU_SUPPORT is not set CONFIG_EXT2_FS=m diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index 2e565f8..80aaaa1 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig @@ -710,7 +710,7 @@ config RTC_DRV_DS1286 config RTC_DRV_DS1302 tristate "Dallas DS1302" - depends on SH_SECUREEDGE5410 + depends on SH_SECUREEDGE5410 || (ARCH_PXA && HIGH_RES_TIMERS) help If you say yes here you get support for the Dallas DS1302 RTC chips. diff --git a/drivers/rtc/rtc-ds1302.c b/drivers/rtc/rtc-ds1302.c index 07e8d79..3c49023 100644 --- a/drivers/rtc/rtc-ds1302.c +++ b/drivers/rtc/rtc-ds1302.c @@ -50,7 +50,7 @@ #define ds1302_set_tx() #define ds1302_set_rx() -static inline int ds1302_hw_init(void) +static inline int ds1302_hw_init(struct platform_device *pdev) { return 0; } @@ -86,6 +86,101 @@ static inline int ds1302_rxbit(void) return !!(get_dp() & RTC_IODATA); } +#elif defined(CONFIG_ARCH_PXA) && defined(CONFIG_HIGH_RES_TIMERS) + +#include +#include + +#define RTC_CE 0x01 +#define RTC_CLK 0x02 +#define RTC_nWE 0x04 +#define RTC_IODATA 0x08 + +static unsigned long ds1302_state; + +static void *mem; + +static inline int ds1302_hw_init(struct platform_device *pdev) +{ + struct resource *r; + + r = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!r) + return -ENODEV; + + mem = devm_ioremap_resource(&pdev->dev, r); + if (!mem) + return -EFAULT; + + return 0; +} + +static inline void ds1302_reset(void) +{ + ds1302_state = 0; + iowrite8(ds1302_state, mem); + usleep_range(4, 5); +} + +static inline void ds1302_clock(void) +{ + usleep_range(1, 2); + ds1302_state |= RTC_CLK; + iowrite8(ds1302_state, mem); + usleep_range(1, 2); + ds1302_state &= ~RTC_CLK; + iowrite8(ds1302_state, mem); +} + +static inline void ds1302_start(void) +{ + ds1302_state &= ~RTC_CLK; + ds1302_state |= RTC_CE; + iowrite8(ds1302_state, mem); + usleep_range(3, 4); +} + +static inline void ds1302_stop(void) +{ + ds1302_state &= ~RTC_CE; + iowrite8(ds1302_state, mem); +} + +static inline void ds1302_set_tx(void) +{ + ds1302_state &= ~RTC_nWE; + iowrite8(ds1302_state, mem); +} + +static inline void ds1302_set_rx(void) +{ + ds1302_state |= RTC_nWE; + iowrite8(ds1302_state, mem); +} + +static inline void ds1302_txbit(int bit) +{ + if (bit) + ds1302_state |= RTC_IODATA; + else + ds1302_state &= ~RTC_IODATA; + iowrite8(ds1302_state, mem); +} + +static inline int ds1302_rxbit(void) +{ + return ioread8(mem) & 0x1; +} + +#ifdef CONFIG_OF +static const struct of_device_id ds1302_dt_ids[] = { + { .compatible = "dallas,rtc-ds1302" }, + { } +}; + +MODULE_DEVICE_TABLE(of, ds1302_dt_ids); +#endif + #else #error "Add support for your platform" #endif @@ -216,7 +311,7 @@ static int __init ds1302_rtc_probe(struct platform_device *pdev) { struct rtc_device *rtc; - if (ds1302_hw_init()) { + if (ds1302_hw_init(pdev)) { dev_err(&pdev->dev, "Failed to init communication channel"); return -EINVAL; } @@ -245,6 +340,7 @@ static struct platform_driver ds1302_platform_driver = { .driver = { .name = DRV_NAME, .owner = THIS_MODULE, + .of_match_table = of_match_ptr(ds1302_dt_ids), }, };