From patchwork Sun Dec 1 06:26:16 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Yanovich X-Patchwork-Id: 3261591 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9855DBEEAD for ; Sun, 1 Dec 2013 06:29:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B0A9120498 for ; Sun, 1 Dec 2013 06:29:54 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (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 A3AD320494 for ; Sun, 1 Dec 2013 06:29:53 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Vn0WE-00068I-3O; Sun, 01 Dec 2013 06:28:40 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Vn0Vk-0002Ms-Fy; Sun, 01 Dec 2013 06:28:08 +0000 Received: from mail-lb0-x22e.google.com ([2a00:1450:4010:c04::22e]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Vn0Vh-0002M0-LL for linux-arm-kernel@lists.infradead.org; Sun, 01 Dec 2013 06:28:06 +0000 Received: by mail-lb0-f174.google.com with SMTP id c11so7712976lbj.5 for ; Sat, 30 Nov 2013 22:27:44 -0800 (PST) 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=INWxrR/1/UDVqRLAXISI10rB0zEiViNKL5E1vnLIHCc=; b=rvxe3ZR30vmA6F1H4uTK1u3BBLc+hUa22VTnny65sTD+y3XjRJqt8gTC9ZZHAQNILf P96/ZvMmMfN+Ij8LwwWo0zzfz/5x96TlfGissTOjB6bdi13h40bWab2dKC5WNc5FRbgG NECCQZxNwIGGuU7o0/aUFMwihRyTssdtHnpQ5C+3spRYjZZ2cW8EFXgAT3u4weVVXnB5 fXuWkreP528T9m6w9vljWGUlo1EzVDQ2nsHEfp5XkkvV/Ui5Evr7CHEixS7yQo2xV9p6 xedmwttJq4QpXIgpODOCRQgGRvlPI1sqJnTQVowTiC9kSrCl4pWMttopYg0d3k/L4P6l BRyw== X-Received: by 10.112.16.137 with SMTP id g9mr13641516lbd.1.1385879264006; Sat, 30 Nov 2013 22:27:44 -0800 (PST) Received: from host5.omatika.ru (0893675324.static.corbina.ru. [95.31.1.192]) by mx.google.com with ESMTPSA id e10sm82577921laa.6.2013.11.30.22.27.42 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 30 Nov 2013 22:27:43 -0800 (PST) From: Sergei Ianovich To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 03/11] rtc: support DS1302 RTC on ICP DAS LP-8x4x Date: Sun, 1 Dec 2013 10:26:16 +0400 Message-Id: <1385879185-22455-4-git-send-email-ynvich@gmail.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1385879185-22455-1-git-send-email-ynvich@gmail.com> References: <1385879185-22455-1-git-send-email-ynvich@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131201_012805_857825_0F95BB6E X-CRM114-Status: GOOD ( 18.51 ) X-Spam-Score: -1.9 (-) Cc: Sergei Ianovich , Eric Miao , Russell King , Haojian Zhuang , Alessandro Zummo 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=-3.9 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RCVD_IN_SBL, RP_MATCHES_RCVD, T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=no 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 --- arch/arm/configs/lp8x4x_defconfig | 1 + arch/arm/mach-pxa/include/mach/lp8x4x.h | 1 + arch/arm/mach-pxa/lp8x4x.c | 8 ++++ drivers/rtc/Kconfig | 2 +- drivers/rtc/rtc-ds1302.c | 85 +++++++++++++++++++++++++++++++++ 5 files changed, 96 insertions(+), 1 deletion(-) diff --git a/arch/arm/configs/lp8x4x_defconfig b/arch/arm/configs/lp8x4x_defconfig index 5cd6d38..27831e4 100644 --- a/arch/arm/configs/lp8x4x_defconfig +++ b/arch/arm/configs/lp8x4x_defconfig @@ -1745,6 +1745,7 @@ CONFIG_RTC_INTF_DEV=y # # CONFIG_RTC_DRV_CMOS is not set # CONFIG_RTC_DRV_DS1286 is not set +CONFIG_RTC_DRV_DS1302=y # CONFIG_RTC_DRV_DS1511 is not set # CONFIG_RTC_DRV_DS1553 is not set # CONFIG_RTC_DRV_DS1742 is not set diff --git a/arch/arm/mach-pxa/include/mach/lp8x4x.h b/arch/arm/mach-pxa/include/mach/lp8x4x.h index 8c501fd..d8a1376 100644 --- a/arch/arm/mach-pxa/include/mach/lp8x4x.h +++ b/arch/arm/mach-pxa/include/mach/lp8x4x.h @@ -48,6 +48,7 @@ #define LP8X4X_CLRHILVINT LP8X4X_P2V(0x17009016) #define LP8X4X_ENFALLINT LP8X4X_P2V(0x17009018) #define LP8X4X_CLRFALLINT LP8X4X_P2V(0x1700901a) +#define LP8X4X_RWRTC LP8X4X_P2V(0x1700901c) /* board specific IRQs */ diff --git a/arch/arm/mach-pxa/lp8x4x.c b/arch/arm/mach-pxa/lp8x4x.c index 0b77e7a..a31b556 100644 --- a/arch/arm/mach-pxa/lp8x4x.c +++ b/arch/arm/mach-pxa/lp8x4x.c @@ -386,11 +386,19 @@ static struct platform_device lp8x4x_dm9000_device[2] = { }, }; +static struct platform_device lp8x4x_ds1302_device[] = { + { + .name = "rtc-ds1302", + .id = 0, + }, +}; + static struct platform_device *lp8x4x_devices[] __initdata = { &lp8x4x_flash_device[0], &lp8x4x_flash_device[1], &lp8x4x_dm9000_device[0], &lp8x4x_dm9000_device[1], + &lp8x4x_ds1302_device[0], }; static struct pxaohci_platform_data lp8x4x_ohci_platform_data = { diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index 0077302..59213c0 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig @@ -676,7 +676,7 @@ config RTC_DRV_DS1286 config RTC_DRV_DS1302 tristate "Dallas DS1302" - depends on SH_SECUREEDGE5410 + depends on SH_SECUREEDGE5410 || MACH_LP8X4X 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..770587b 100644 --- a/drivers/rtc/rtc-ds1302.c +++ b/drivers/rtc/rtc-ds1302.c @@ -86,6 +86,91 @@ static inline int ds1302_rxbit(void) return !!(get_dp() & RTC_IODATA); } +#elif defined(CONFIG_MACH_LP8X4X) + +#include +#include +#include + +#define RTC_CE 0x01 +#define RTC_CLK 0x02 +#define RTC_nWE 0x04 +#define RTC_IODATA 0x08 + +static unsigned long ds1302_state; + +void nsleep(unsigned long nanosec) +{ + ktime_t t = ns_to_ktime(nanosec); + long state = current->state; + + __set_current_state(TASK_UNINTERRUPTIBLE); + schedule_hrtimeout(&t, HRTIMER_MODE_REL); + __set_current_state(state); +} + +static inline int ds1302_hw_init(void) +{ + return 0; +} + +static inline void ds1302_reset(void) +{ + ds1302_state = 0; + iowrite8(ds1302_state, LP8X4X_RWRTC); + nsleep(4000); +} + +static inline void ds1302_clock(void) +{ + nsleep(1000); + ds1302_state |= RTC_CLK; + iowrite8(ds1302_state, LP8X4X_RWRTC); + nsleep(1000); + ds1302_state &= ~RTC_CLK; + iowrite8(ds1302_state, LP8X4X_RWRTC); +} + +static inline void ds1302_start(void) +{ + ds1302_state &= ~RTC_CLK; + ds1302_state |= RTC_CE; + iowrite8(ds1302_state, LP8X4X_RWRTC); + nsleep(3000); +} + +static inline void ds1302_stop(void) +{ + ds1302_state &= ~RTC_CE; + iowrite8(ds1302_state, LP8X4X_RWRTC); +} + +static inline void ds1302_set_tx(void) +{ + ds1302_state &= ~RTC_nWE; + iowrite8(ds1302_state, LP8X4X_RWRTC); +} + +static inline void ds1302_set_rx(void) +{ + ds1302_state |= RTC_nWE; + iowrite8(ds1302_state, LP8X4X_RWRTC); +} + +static inline void ds1302_txbit(int bit) +{ + if (bit) + ds1302_state |= RTC_IODATA; + else + ds1302_state &= ~RTC_IODATA; + iowrite8(ds1302_state, LP8X4X_RWRTC); +} + +static inline int ds1302_rxbit(void) +{ + return ioread8(LP8X4X_RWRTC) & 0x1; +} + #else #error "Add support for your platform" #endif