From patchwork Wed Jul 6 08:43:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephan Roslen X-Patchwork-Id: 645161 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-lf0-x23d.google.com (mail-lf0-x23d.google.com [IPv6:2a00:1450:4010:c07::23d]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rkvQz22SVz9s9W for ; Wed, 6 Jul 2016 18:43:06 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b=P23J4+0w; dkim-atps=neutral Received: by mail-lf0-x23d.google.com with SMTP id a4sf73705490lfa.0 for ; Wed, 06 Jul 2016 01:43:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=sender:from:subject:to:message-id:date:user-agent:mime-version :x-original-sender:x-original-authentication-results:reply-to :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post :list-help:list-archive:list-subscribe:list-unsubscribe; bh=vEccBn5Qt1C3xHsg/3//O2ExnKwxySQDVzBnKB9ffhg=; b=P23J4+0wwp72h0DjsOigVAACvt5ZZ0n/i8Bv2mXIi9JmrjvdzcvV5f0wHBZnirZcyR 1478PatwJ4BIqdSLqnWqWRUhje2Z/TykRBXe1CIAAJwxcV6h5y9oTddKh5E6+s8L3FPB GNHJx9Zq+A1vPJy2BtT5rRf8P1DoRhTcIKZE3vs7AOfQcpwU1kg0sze9UpfTjS9BLMR/ KbZWIbaEgHJVJmNzVl9UqGYfYRYBYOqKW84jNdrSqlS/ZRklCBdkmnktDkZxf4DM4zFG 93KCAX1aAmZD0yesaIIDaSKE7C4XQIMGQW0la9q5nT5agpYgvxF+GYu3bp7w3eyl6d8y zdiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=sender:x-gm-message-state:from:subject:to:message-id:date :user-agent:mime-version:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=vEccBn5Qt1C3xHsg/3//O2ExnKwxySQDVzBnKB9ffhg=; b=aUfpdXX4vRcZFCp9SRhISkyLGXLDMP+yiQlBIJ1krQ+Xj2YY7hB7NgjlEPuLYaPAYF 98Ic3GmM26O9ZIMUXho+avW/AaigWy69ia9SE6jYwd0Y47GWf2h3O5YWZMcaKbKN6Ry2 Loa3AZFk2hh6NqScBXjkIDx9uVgzYY3ZerXH7RpDimMwwoE4V2+ingtf2JyNm88GyuVr wMg+8kOalf5yB9NnIMkpTmhwrfTDqzPxNgkXWbBQjau0qbPVCxmS2UIJvkBfGFv+28aB LZ0LmpbuFOuTvtetNts2RnNhiWJ4D1MXor8UpX7mc3HY7s97u7bnSqO3t4f7XWLOZlFt F4/Q== Sender: rtc-linux@googlegroups.com X-Gm-Message-State: ALyK8tJGJJ9yziS+7cCnkMTF3C65MvvKIi1Ey5YyWQT3AzF9ctvZz4fivuRZJjiLdJKsmQ== X-Received: by 10.46.33.231 with SMTP id h100mr157076lji.13.1467794583875; Wed, 06 Jul 2016 01:43:03 -0700 (PDT) X-BeenThere: rtc-linux@googlegroups.com Received: by 10.46.32.7 with SMTP id g7ls208502ljg.77.gmail; Wed, 06 Jul 2016 01:43:03 -0700 (PDT) X-Received: by 10.46.33.31 with SMTP id h31mr7468389ljh.4.1467794583112; Wed, 06 Jul 2016 01:43:03 -0700 (PDT) Received: from mail-out1.kundencontroller.de (mail-out1.kundencontroller.de. [85.31.184.34]) by gmr-mx.google.com with ESMTPS id c135si249246wme.2.2016.07.06.01.43.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Jul 2016 01:43:03 -0700 (PDT) Received-SPF: neutral (google.com: 85.31.184.34 is neither permitted nor denied by best guess record for domain of stephan@roslen.de) client-ip=85.31.184.34; Received: from [192.168.163.129] (unknown [213.168.84.195]) (using TLSv1.2 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: pop166796-stephan) by mail-out1.kundencontroller.de (Postfix) with ESMTPSA id 601CB18054AB; Wed, 6 Jul 2016 10:43:01 +0200 (CEST) From: Stephan Roslen Subject: [rtc-linux] [PATCH] rtc: sunxi: use external oscillator To: a.zummo@towertech.it, alexandre.belloni@free-electrons.com, maxime.ripard@free-electrons.com, wens@csie.org, rtc-linux@googlegroups.com Message-ID: <577CC494.8020103@roslen.de> Date: Wed, 6 Jul 2016 10:43:00 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 MIME-Version: 1.0 X-Original-Sender: stephan@roslen.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 85.31.184.34 is neither permitted nor denied by best guess record for domain of stephan@roslen.de) smtp.mailfrom=stephan@roslen.de Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: rtc-linux@googlegroups.com X-Google-Group-Id: 712029733259 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , We noticed some serious drift problems in Allwinner A20 RTCs. I found out, that the oscillator source needs to be set to an external 32.768 KHz oscillator instead of the internal 32.000 KHz oscillator. Signed-off-by: Stephan Roslen --- drivers/rtc/rtc-sunxi.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/rtc/rtc-sunxi.c b/drivers/rtc/rtc-sunxi.c index abada60..001256e 100644 --- a/drivers/rtc/rtc-sunxi.c +++ b/drivers/rtc/rtc-sunxi.c @@ -34,9 +34,19 @@ #include #define SUNXI_LOSC_CTRL 0x0000 + +/* magic number required to set bit 0 */ +#define SUNXI_LOSC_CTRL_KEY 0x16AA0000 + +#define SUNXI_LOSC_CTRL_AUTO_SWT_EN BIT(14) + #define SUNXI_LOSC_CTRL_RTC_HMS_ACC BIT(8) #define SUNXI_LOSC_CTRL_RTC_YMD_ACC BIT(7) +#define SUNXI_LOSC_CTRL_EXT_GSM1 BIT(3) +#define SUNXI_LOSC_CTRL_EXT_GSM0 BIT(2) +#define SUNXI_LOSC_CTRL_SRC_SEL BIT(0) + #define SUNXI_RTC_YMD 0x0004 #define SUNXI_RTC_HMS 0x0008 @@ -438,6 +448,8 @@ static int sunxi_rtc_probe(struct platform_device *pdev) struct resource *res; int ret; + uint32_t loscctrl; + chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); if (!chip) return -ENOMEM; @@ -468,6 +480,19 @@ static int sunxi_rtc_probe(struct platform_device *pdev) return -ENODEV; } + loscctrl = readl(chip->base + SUNXI_LOSC_CTRL); + loscctrl &= ~(SUNXI_LOSC_CTRL_AUTO_SWT_EN); + loscctrl |= (SUNXI_LOSC_CTRL_SRC_SEL | SUNXI_LOSC_CTRL_KEY); + loscctrl |= SUNXI_LOSC_CTRL_EXT_GSM1; + writel(loscctrl, chip->base + SUNXI_LOSC_CTRL); + udelay(100); + + loscctrl = readl(chip->base + SUNXI_LOSC_CTRL); + if (!(loscctrl & SUNXI_LOSC_CTRL_SRC_SEL)) { + dev_err(&pdev->dev, "Error: Set LOSC to external failed.\n"); + dev_err(&pdev->dev, "Warning: RTC time will be wrong!\n"); + } + /* clear the alarm count value */ writel(0, chip->base + SUNXI_ALRM_DHMS);