From patchwork Sat Jul 2 15:28:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 643509 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-lf0-x23b.google.com (mail-lf0-x23b.google.com [IPv6:2a00:1450:4010:c07::23b]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rhccR3J3hz9s3v for ; Sun, 3 Jul 2016 01:28:22 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b=eb8UQdwN; dkim-atps=neutral Received: by mail-lf0-x23b.google.com with SMTP id a4sf51716867lfa.0 for ; Sat, 02 Jul 2016 08:28:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding: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=mUAXdbsqKCNwWyU+wgWnr5mJC+97UQqFaLamIfsBcrc=; b=eb8UQdwNHtAz4vF8Su1+HZth8Z2hN929ly7g94AEh8eW5jWtcRXHVJwm5DZx80MZ+s 3qURp5FcPOoTAeRAkHYwc8XpRWsaRd312PPI3H3KruZvcFnFv4y23+mFisto0e4ylkMk UKY5qRASFzldHF09Os41oqRh/6xUM7fv5Gsndom/4zzP6jb7TLdBb8fJy2xKQakc58mD kDs8VyPHLRN9Uujvc1Ozlmmdes9qpr9pnTo66I0RP9ub8296cWH6fVsQoYQkcYiDLsFQ ZA1bYC+rR6Mi+kiX3xfwCggvOqKkPVjqbbJl+rpzcvuHBJaVO/06oM8XeD/5J+yHA+1J pvRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=sender:x-gm-message-state:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding :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=mUAXdbsqKCNwWyU+wgWnr5mJC+97UQqFaLamIfsBcrc=; b=dQxo8FaPAjf4iPwiC/NX4U5jxkwoyqkYyNHiNdiFjtLlG0rQQ5x/aE6MJsdClT1dM/ DIB3UtGUhPKayxgc5amE3pm0zj05oKPRsztWCGeJmBp07BJsu6fUltkiDTXfJoMWfu4l GkmJvHf1dwMJU4MKnldywxikSFMI89L78Pgz/2XJzszNsb2KTQt5G3tD2Qd38+iR2Gvh +dhQKd7mjn1hGGUPIjoEHsujcqaxUdgmCv9GSznHlu3QD54dRzF+u4nkMHMZvdm6ducq MRVsHgBpZT2ltivehfXEt22vKwl5c8X251zbMwbxBIqjF+PhTuF3ZW/JOotPDpIinDRg Kunw== Sender: rtc-linux@googlegroups.com X-Gm-Message-State: ALyK8tKbkieGFLnCtls/ez8R3EqxLwZN9SCvFKhNFxFNMfYWHYI9aehCHtnAfqe071B8Yg== X-Received: by 10.25.206.202 with SMTP id e193mr105743lfg.9.1467473300019; Sat, 02 Jul 2016 08:28:20 -0700 (PDT) X-BeenThere: rtc-linux@googlegroups.com Received: by 10.25.21.87 with SMTP id l84ls108209lfi.72.gmail; Sat, 02 Jul 2016 08:28:19 -0700 (PDT) X-Received: by 10.25.163.17 with SMTP id m17mr4755123lfe.1.1467473299301; Sat, 02 Jul 2016 08:28:19 -0700 (PDT) Received: from arcturus.kleine-koenig.org (arcturus.kleine-koenig.org. [2a01:4f8:d12:1f44::2]) by gmr-mx.google.com with ESMTPS id x70si239117wmf.1.2016.07.02.08.28.19 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Jul 2016 08:28:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of uwe@kleine-koenig.org designates 2a01:4f8:d12:1f44::2 as permitted sender) client-ip=2a01:4f8:d12:1f44::2; Received: by arcturus.kleine-koenig.org (Postfix, from userid 1000) id C41BAAF3DE; Sat, 2 Jul 2016 17:28:18 +0200 (CEST) From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= To: Alessandro Zummo , Alexandre Belloni Cc: rtc-linux@googlegroups.com, =?UTF-8?q?Manuel=20R=C3=B6der?= Subject: [rtc-linux] [PATCH v2 1/5] rtc: s35390a: fix reading out alarm Date: Sat, 2 Jul 2016 17:28:08 +0200 Message-Id: <1467473292-26371-2-git-send-email-uwe@kleine-koenig.org> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1467473292-26371-1-git-send-email-uwe@kleine-koenig.org> References: <1467473292-26371-1-git-send-email-uwe@kleine-koenig.org> MIME-Version: 1.0 X-Original-Sender: uwe@kleine-koenig.org X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: best guess record for domain of uwe@kleine-koenig.org designates 2a01:4f8:d12:1f44::2 as permitted sender) smtp.mailfrom=uwe@kleine-koenig.org 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: , There are several issues fixed in this patch: - When alarm isn't enabled, set .enabled to zero instead of returning -EINVAL. - Ignore how IRQ1 is configured when determining if IRQ2 is on. - The three alarm registers have an enable flag which must be evaluated. - The chip always triggers when the seconds register gets 0. Note that the rtc framework however doesn't handle the result correctly because it doesn't check wday being initialized and so interprets an alarm being set for 10:00 AM in three days as 10:00 AM tomorrow (or today if that's not over yet). Signed-off-by: Uwe Kleine-König --- drivers/rtc/rtc-s35390a.c | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/drivers/rtc/rtc-s35390a.c b/drivers/rtc/rtc-s35390a.c index f40afdd0e5f5..6507a01cf9ad 100644 --- a/drivers/rtc/rtc-s35390a.c +++ b/drivers/rtc/rtc-s35390a.c @@ -242,6 +242,8 @@ static int s35390a_set_alarm(struct i2c_client *client, struct rtc_wkalrm *alm) if (alm->time.tm_wday != -1) buf[S35390A_ALRM_BYTE_WDAY] = bin2bcd(alm->time.tm_wday) | 0x80; + else + buf[S35390A_ALRM_BYTE_WDAY] = 0; buf[S35390A_ALRM_BYTE_HOURS] = s35390a_hr2reg(s35390a, alm->time.tm_hour) | 0x80; @@ -269,23 +271,43 @@ static int s35390a_read_alarm(struct i2c_client *client, struct rtc_wkalrm *alm) if (err < 0) return err; - if (bitrev8(sts) != S35390A_INT2_MODE_ALARM) - return -EINVAL; + if ((bitrev8(sts) & S35390A_INT2_MODE_MASK) != S35390A_INT2_MODE_ALARM) { + /* + * When the alarm isn't enabled, the register to configure + * the alarm time isn't accessible. + */ + alm->enabled = 0; + return 0; + } else { + alm->enabled = 1; + } err = s35390a_get_reg(s35390a, S35390A_CMD_INT2_REG1, buf, sizeof(buf)); if (err < 0) return err; /* This chip returns the bits of each byte in reverse order */ - for (i = 0; i < 3; ++i) { + for (i = 0; i < 3; ++i) buf[i] = bitrev8(buf[i]); - buf[i] &= ~0x80; - } - alm->time.tm_wday = bcd2bin(buf[S35390A_ALRM_BYTE_WDAY]); - alm->time.tm_hour = s35390a_reg2hr(s35390a, - buf[S35390A_ALRM_BYTE_HOURS]); - alm->time.tm_min = bcd2bin(buf[S35390A_ALRM_BYTE_MINS]); + /* + * B0 of the three matching registers is an enable flag. Iff it is set + * the configured value is used for matching. + */ + if (buf[S35390A_ALRM_BYTE_WDAY] & 0x80) + alm->time.tm_wday = + bcd2bin(buf[S35390A_ALRM_BYTE_WDAY] & ~0x80); + + if (buf[S35390A_ALRM_BYTE_HOURS] & 0x80) + alm->time.tm_hour = + s35390a_reg2hr(s35390a, + buf[S35390A_ALRM_BYTE_HOURS] & ~0x80); + + if (buf[S35390A_ALRM_BYTE_MINS] & 0x80) + alm->time.tm_min = bcd2bin(buf[S35390A_ALRM_BYTE_MINS] & ~0x80); + + /* alarm triggers always at s=0 */ + alm->time.tm_sec = 0; dev_dbg(&client->dev, "%s: alm is mins=%d, hours=%d, wday=%d\n", __func__, alm->time.tm_min, alm->time.tm_hour,