Bug#693997: drivers/rtc/rtc-s35390a.c: add wakealarm support for rtc-s35390A rtc chip

2013-01-25 Thread Martin Michlmayr
* Martin Michlmayr t...@cyrius.com [2012-11-22 18:44]:
 The following patch adds wakealarm support for rtc-s35390A rtc chip,
 which is used by some QNAP devices:
 https://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=commit;h=542dd33a4925757c93b2c811b19434822a6c1a73
 
 Can you add this patch to the wheezy kernel?

I just applide this patch to the wheezy kernel.  It applies with just
minor fuzz, and it works correctly, as tested on a QNAP TS-219.

I've applied the patch from above with the fuzz fixed.  Can you please
put this into wheezy?

-- 
Martin Michlmayr
http://www.cyrius.com/
From: Michael Langer michael.brainbug.lan...@googlemail.com
Date: Fri, 5 Oct 2012 00:14:37 + (-0700)
Subject: drivers/rtc/rtc-s35390a.c: add wakealarm support for rtc-s35390A rtc chip
X-Git-Tag: v3.7-rc1~110^2~73
X-Git-Url: https://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Ftorvalds%2Flinux.git;a=commitdiff_plain;h=542dd33a4925757c93b2c811b19434822a6c1a73;hp=48e9766726ebb8f5d98823fe6b32dff570bc04d8

drivers/rtc/rtc-s35390a.c: add wakealarm support for rtc-s35390A rtc chip

Add basic get/set alarm support for the Seiko Instruments S-35390A.  The
chip is used on the QNAP TS-219P+ NAS device.

Signed-off-by: Michael Langer michael.brainbug.lan...@googlemail.com
Signed-off-by: Andrew Morton a...@linux-foundation.org
Signed-off-by: Linus Torvalds torva...@linux-foundation.org
---

diff --git a/drivers/rtc/rtc-s35390a.c b/drivers/rtc/rtc-s35390a.c
index cc5c516..8a09232 100644
--- a/drivers/rtc/rtc-s35390a.c
+++ b/drivers/rtc/rtc-s35390a.c
@@ -19,6 +19,8 @@
 #define S35390A_CMD_STATUS1	0
 #define S35390A_CMD_STATUS2	1
 #define S35390A_CMD_TIME1	2
+#define S35390A_CMD_TIME2	3
+#define S35390A_CMD_INT2_REG1	5
 
 #define S35390A_BYTE_YEAR	0
 #define S35390A_BYTE_MONTH	1
@@ -28,12 +30,23 @@
 #define S35390A_BYTE_MINS	5
 #define S35390A_BYTE_SECS	6
 
+#define S35390A_ALRM_BYTE_WDAY	0
+#define S35390A_ALRM_BYTE_HOURS	1
+#define S35390A_ALRM_BYTE_MINS	2
+
 #define S35390A_FLAG_POC	0x01
 #define S35390A_FLAG_BLD	0x02
 #define S35390A_FLAG_24H	0x40
 #define S35390A_FLAG_RESET	0x80
 #define S35390A_FLAG_TEST	0x01
 
+#define S35390A_INT2_MODE_MASK		0xF0
+
+#define S35390A_INT2_MODE_NOINTR	0x00
+#define S35390A_INT2_MODE_FREQ		0x10
+#define S35390A_INT2_MODE_ALARM		0x40
+#define S35390A_INT2_MODE_PMIN_EDG	0x20
+
 static const struct i2c_device_id s35390a_id[] = {
 	{ s35390a, 0 },
 	{ }
@@ -184,6 +197,104 @@
 	return rtc_valid_tm(tm);
 }
 
+static int s35390a_set_alarm(struct i2c_client *client, struct rtc_wkalrm *alm)
+{
+	struct s35390a *s35390a = i2c_get_clientdata(client);
+	char buf[3], sts = 0;
+	int err, i;
+
+	dev_dbg(client-dev, %s: alm is secs=%d, mins=%d, hours=%d mday=%d, \
+		mon=%d, year=%d, wday=%d\n, __func__, alm-time.tm_sec,
+		alm-time.tm_min, alm-time.tm_hour, alm-time.tm_mday,
+		alm-time.tm_mon, alm-time.tm_year, alm-time.tm_wday);
+
+	/* disable interrupt */
+	err = s35390a_set_reg(s35390a, S35390A_CMD_STATUS2, sts, sizeof(sts));
+	if (err  0)
+		return err;
+
+	/* clear pending interrupt, if any */
+	err = s35390a_get_reg(s35390a, S35390A_CMD_STATUS1, sts, sizeof(sts));
+	if (err  0)
+		return err;
+
+	if (alm-enabled)
+		sts = S35390A_INT2_MODE_ALARM;
+	else
+		sts = S35390A_INT2_MODE_NOINTR;
+
+	/* This chip expects the bits of each byte to be in reverse order */
+	sts = bitrev8(sts);
+
+	/* set interupt mode*/
+	err = s35390a_set_reg(s35390a, S35390A_CMD_STATUS2, sts, sizeof(sts));
+	if (err  0)
+		return err;
+
+	if (alm-time.tm_wday != -1)
+		buf[S35390A_ALRM_BYTE_WDAY] = bin2bcd(alm-time.tm_wday) | 0x80;
+
+	buf[S35390A_ALRM_BYTE_HOURS] = s35390a_hr2reg(s35390a,
+			alm-time.tm_hour) | 0x80;
+	buf[S35390A_ALRM_BYTE_MINS] = bin2bcd(alm-time.tm_min) | 0x80;
+
+	if (alm-time.tm_hour = 12)
+		buf[S35390A_ALRM_BYTE_HOURS] |= 0x40;
+
+	for (i = 0; i  3; ++i)
+		buf[i] = bitrev8(buf[i]);
+
+	err = s35390a_set_reg(s35390a, S35390A_CMD_INT2_REG1, buf,
+sizeof(buf));
+
+	return err;
+}
+
+static int s35390a_read_alarm(struct i2c_client *client, struct rtc_wkalrm *alm)
+{
+	struct s35390a *s35390a = i2c_get_clientdata(client);
+	char buf[3], sts;
+	int i, err;
+
+	err = s35390a_get_reg(s35390a, S35390A_CMD_STATUS2, sts, sizeof(sts));
+	if (err  0)
+		return err;
+
+	if (bitrev8(sts) != S35390A_INT2_MODE_ALARM)
+		return -EINVAL;
+
+	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) {
+		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]);
+
+	dev_dbg(client-dev, %s: alm is mins=%d, hours=%d, wday=%d\n,
+			__func__, alm-time.tm_min, alm-time.tm_hour,
+			alm-time.tm_wday);
+
+	return 0;
+}
+
+static int s35390a_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
+{

Bug#693997: drivers/rtc/rtc-s35390a.c: add wakealarm support for rtc-s35390A rtc chip

2012-11-22 Thread Martin Michlmayr
Package: linux
Version: 3.2.32-1
Severity: wishlist

The following patch adds wakealarm support for rtc-s35390A rtc chip,
which is used by some QNAP devices:
https://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=commit;h=542dd33a4925757c93b2c811b19434822a6c1a73

Can you add this patch to the wheezy kernel?

-- 
Martin Michlmayr
http://www.cyrius.com/


-- 
To UNSUBSCRIBE, email to debian-kernel-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20121122184427.ga31...@jirafa.cyrius.com