From patchwork Thu Jul 15 09:12:02 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rudolf Marek X-Patchwork-Id: 58968 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-fx0-f56.google.com (mail-fx0-f56.google.com [209.85.161.56]) by ozlabs.org (Postfix) with ESMTP id DD01CB6EFF for ; Thu, 15 Jul 2010 19:12:08 +1000 (EST) Received: by fxm17 with SMTP id 17sf187054fxm.11 for ; Thu, 15 Jul 2010 02:12:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=domainkey-signature:received:x-beenthere:received:received:received :received:received-spf:received:received:message-id:date:from :user-agent:mime-version:to:subject:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:list-post:list-help:list-archive:sender:list-subscribe :list-unsubscribe:content-type; bh=BlVLKXa7Z6DRsf2oz/4iJW4pUbpuZKc38SuTIOpYAUc=; b=ZlokX2hP/58Be25gpP76d4gLhUekxE3UPkJH9PVWtKHy7bhLf9cwlNnNRGnA0rYGAX zhk/AhwYzua8JeuwdMVQOsri9JGlUyV/g2ILiU/JrWdNVOsX9ADpLt8bjASv7Y/TR43k OYdOPU9F9TfiwFGj8+ZrBXmZws0juFE9jeuTw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlegroups.com; s=beta; h=x-beenthere:received-spf:message-id:date:from:user-agent :mime-version:to:subject:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:list-post:list-help:list-archive:sender:list-subscribe :list-unsubscribe:content-type; b=YxOGeNyMpWUli+dIuIobjCkEe4TY4YAyq6beFF908yf6V5d5txfC26o1dQBHbZnyzV BVSGgSPlYdNeXjmiaq7e8Dn/Ugc6tlceqD257XGeHcazrY+YSFTi6v8dYwjKlNoR3EYu m0hOisPQFRx6IIGJbixbMVWgl601OOm09zBls= Received: by 10.223.15.79 with SMTP id j15mr14393faa.32.1279185126300; Thu, 15 Jul 2010 02:12:06 -0700 (PDT) X-BeenThere: rtc-linux@googlegroups.com Received: by 10.204.152.197 with SMTP id h5ls2418259bkw.3.p; Thu, 15 Jul 2010 02:12:04 -0700 (PDT) Received: by 10.204.80.167 with SMTP id t39mr834448bkk.11.1279185124400; Thu, 15 Jul 2010 02:12:04 -0700 (PDT) Received: by 10.204.80.167 with SMTP id t39mr834447bkk.11.1279185124366; Thu, 15 Jul 2010 02:12:04 -0700 (PDT) Received: from mail.sysgo.com (mail.sysgo.com [195.145.229.155]) by gmr-mx.google.com with ESMTP id n18si719925bkw.2.2010.07.15.02.12.04; Thu, 15 Jul 2010 02:12:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of rudolf.marek@sysgo.com designates 195.145.229.155 as permitted sender) client-ip=195.145.229.155; Received: from donald.sysgo.com (unknown [172.22.1.30]) by mail.sysgo.com (Postfix) with ESMTP id 8DBDC140AF; Thu, 15 Jul 2010 11:12:03 +0200 (CEST) Received: from [172.24.12.14] (mar.sysgo.cz [172.24.12.14]) by donald.sysgo.com (Postfix) with ESMTP id BADD1344072; Thu, 15 Jul 2010 11:12:01 +0200 (CEST) Message-ID: <4C3ED0E2.10905@sysgo.com> Date: Thu, 15 Jul 2010 11:12:02 +0200 From: Rudolf Marek User-Agent: Mozilla-Thunderbird 2.0.0.22 (X11/20090707) MIME-Version: 1.0 To: rtc-linux@googlegroups.com, Martyn Welch Subject: [rtc-linux] [PATCH] Fix the rx8581 setdatetime X-Original-Sender: rudolf.marek@sysgo.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: best guess record for domain of rudolf.marek@sysgo.com designates 195.145.229.155 as permitted sender) smtp.mail=rudolf.marek@sysgo.com Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: List-Post: , List-Help: , List-Archive: Sender: rtc-linux@googlegroups.com List-Subscribe: , List-Unsubscribe: , Hello, This patch fixes the logic while writing new date/time to the chip. The driver incorrectly written back register values to different registers and even with wrong mask. The patch adds clearing of the VLF register, which should be cleared if all date/time values are set. Signed-off-by: Rudolf Marek I'm attaching this as an attachment because Thunderbird will break it otherwise. For your reference, datasheet is here: http://www.epsontoyocom.co.jp/english/product/RTC/set03/ra8581sa/index.html Thanks, Rudolf Acked-by: Wan ZongShun This patch fixes the logic while writing new date/time to the chip. The driver incorrectly written back register values to different registers and even with wrong mask. The patch adds clearing of the VLF register, which should be cleared if all date/time values are set. Signed-off-by: Rudolf Marek Index: linux/drivers/rtc/rtc-rx8581.c =================================================================== --- linux.orig/drivers/rtc/rtc-rx8581.c 2010-07-12 11:21:27.000000000 +0200 +++ linux/drivers/rtc/rtc-rx8581.c 2010-07-12 12:30:01.000000000 +0200 @@ -168,7 +168,7 @@ return -EIO; } - err = i2c_smbus_write_byte_data(client, RX8581_REG_FLAG, + err = i2c_smbus_write_byte_data(client, RX8581_REG_CTRL, (data | RX8581_CTRL_STOP)); if (err < 0) { dev_err(&client->dev, "Unable to write control register\n"); @@ -182,6 +182,20 @@ return -EIO; } + /* get VLF and clear it */ + data = i2c_smbus_read_byte_data(client, RX8581_REG_FLAG); + if (data < 0) { + dev_err(&client->dev, "Unable to read flag register\n"); + return -EIO; + } + + err = i2c_smbus_write_byte_data(client, RX8581_REG_FLAG, + (data & ~(RX8581_FLAG_VLF))); + if (err != 0) { + dev_err(&client->dev, "Unable to write flag register\n"); + return -EIO; + } + /* Restart the clock */ data = i2c_smbus_read_byte_data(client, RX8581_REG_CTRL); if (data < 0) { @@ -189,8 +203,8 @@ return -EIO; } - err = i2c_smbus_write_byte_data(client, RX8581_REG_FLAG, - (data | ~(RX8581_CTRL_STOP))); + err = i2c_smbus_write_byte_data(client, RX8581_REG_CTRL, + (data & ~(RX8581_CTRL_STOP))); if (err != 0) { dev_err(&client->dev, "Unable to write control register\n"); return -EIO;