Re: [rtc-linux] [PATCH 1/2] rtc: add rtc-m41t80 driver (take 2)

2007-06-22 Thread Alessandro Zummo
On Fri, 22 Jun 2007 22:13:20 +0900 (JST)
Atsushi Nemoto <[EMAIL PROTECTED]> wrote:

> This is a new-style i2c driver for ST M41T80 series RTC chip, derived
> from works by Alexander Bigga <[EMAIL PROTECTED]> who wrote the original
> rtc-m41txx.c based on drivers/i2c/chips/m41t00.c driver.
> 
> This driver supports M41T8[0-4] and M41ST8[457].  The old m41t00
> driver supports M41T00, M41T81 and M41T85(M41ST85).  While the M41T00
> chip is now supported by rtc-ds1307 driver, this driver does not
> include support for the chip.
> 
> Signed-off-by: Atsushi Nemoto <[EMAIL PROTECTED]>
> Signed-off-by: Alexander Bigga <[EMAIL PROTECTED]>
> Acked-by: Mark A. Greer <[EMAIL PROTECTED]>

 Acked-by: Alessandro Zummo <[EMAIL PROTECTED]>

-- 

 Best regards,

 Alessandro Zummo,
  Tower Technologies - Torino, Italy

  http://www.towertech.it

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/2] rtc: add rtc-m41t80 driver (take 2)

2007-06-22 Thread Atsushi Nemoto
This is a new-style i2c driver for ST M41T80 series RTC chip, derived
from works by Alexander Bigga <[EMAIL PROTECTED]> who wrote the original
rtc-m41txx.c based on drivers/i2c/chips/m41t00.c driver.

This driver supports M41T8[0-4] and M41ST8[457].  The old m41t00
driver supports M41T00, M41T81 and M41T85(M41ST85).  While the M41T00
chip is now supported by rtc-ds1307 driver, this driver does not
include support for the chip.

Signed-off-by: Atsushi Nemoto <[EMAIL PROTECTED]>
Signed-off-by: Alexander Bigga <[EMAIL PROTECTED]>
Acked-by: Mark A. Greer <[EMAIL PROTECTED]>
---
Changes from previous version (v0.04):

* Add "sqwfreq" sysfs attribute
* Remove m41t80.h
* Fix handling of return value from i2c_smbus_read_byte_data()

 drivers/rtc/Kconfig  |   12 +
 drivers/rtc/Makefile |1 +
 drivers/rtc/rtc-m41t80.c |  629 ++
 3 files changed, 642 insertions(+), 0 deletions(-)

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 4e4c10a..03d2b1d 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -282,6 +282,18 @@ config RTC_DRV_DS1742
  This driver can also be built as a module. If so, the module
  will be called rtc-ds1742.
 
+config RTC_DRV_M41T80
+   tristate "ST M41T80 series RTC"
+   depends on RTC_CLASS && I2C
+   help
+ If you say Y here you will get support for the
+ ST M41T80 RTC chips series. Currently following chips are
+ supported: M41T80, M41T81, M41T82, M41T83, M41ST84, M41ST85
+ and M41ST87.
+
+ This driver can also be built as a module. If so, the module
+ will be called rtc-m41t80.
+
 config RTC_DRV_M48T86
tristate "ST M48T86/Dallas DS12887"
depends on RTC_CLASS
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index a1afbc2..d1dc270 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -28,6 +28,7 @@ obj-$(CONFIG_RTC_DRV_PCF8583) += rtc-pcf8583.o
 obj-$(CONFIG_RTC_DRV_RS5C372)  += rtc-rs5c372.o
 obj-$(CONFIG_RTC_DRV_S3C)  += rtc-s3c.o
 obj-$(CONFIG_RTC_DRV_RS5C348)  += rtc-rs5c348.o
+obj-$(CONFIG_RTC_DRV_M41T80)   += rtc-m41t80.o
 obj-$(CONFIG_RTC_DRV_M48T86)   += rtc-m48t86.o
 obj-$(CONFIG_RTC_DRV_DS1553)   += rtc-ds1553.o
 obj-$(CONFIG_RTC_DRV_RS5C313)  += rtc-rs5c313.o
diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c
new file mode 100644
index 000..51d8da8
--- /dev/null
+++ b/drivers/rtc/rtc-m41t80.c
@@ -0,0 +1,629 @@
+/*
+ * I2C client/driver for the ST M41T80 family of i2c rtc chips.
+ *
+ * Author: Alexander Bigga <[EMAIL PROTECTED]>
+ *
+ * Based on m41t00.c by Mark A. Greer <[EMAIL PROTECTED]>
+ *
+ * 2006 (c) mycable GmbH
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define M41T80_REG_SSEC0
+#define M41T80_REG_SEC 1
+#define M41T80_REG_MIN 2
+#define M41T80_REG_HOUR3
+#define M41T80_REG_WDAY4
+#define M41T80_REG_DAY 5
+#define M41T80_REG_MON 6
+#define M41T80_REG_YEAR7
+#define M41T80_REG_ALARM_MON   0xa
+#define M41T80_REG_ALARM_DAY   0xb
+#define M41T80_REG_ALARM_HOUR  0xc
+#define M41T80_REG_ALARM_MIN   0xd
+#define M41T80_REG_ALARM_SEC   0xe
+#define M41T80_REG_FLAGS   0xf
+#define M41T80_REG_SQW 0x13
+
+#define M41T80_DATETIME_REG_SIZE   (M41T80_REG_YEAR + 1)
+#define M41T80_ALARM_REG_SIZE  \
+   (M41T80_REG_ALARM_SEC + 1 - M41T80_REG_ALARM_MON)
+
+#define M41T80_SEC_ST  (1 << 7)/* ST: Stop Bit */
+#define M41T80_ALMON_AFE   (1 << 7)/* AFE: AF Enable Bit */
+#define M41T80_ALMON_SQWE  (1 << 6)/* SQWE: SQW Enable Bit */
+#define M41T80_ALHOUR_HT   (1 << 6)/* HT: Halt Update Bit */
+#define M41T80_FLAGS_AF(1 << 6)/* AF: Alarm Flag Bit */
+#define M41T80_FLAGS_BATT_LOW  (1 << 4)/* BL: Battery Low Bit */
+
+#define M41T80_FEATURE_HT  (1 << 0)
+#define M41T80_FEATURE_BL  (1 << 1)
+
+#define DRV_VERSION "0.05"
+
+struct m41t80_chip_info {
+   const char *name;
+   u8 features;
+};
+
+static const struct m41t80_chip_info m41t80_chip_info_tbl[] = {
+   {
+   .name   = "m41t80",
+   .features   = 0,
+   },
+   {
+   .name   = "m41t81",
+   .features   = M41T80_FEATURE_HT,
+   },
+   {
+   .name   = "m41t81s",
+   .features   = M41T80_FEATURE_HT | M41T80_FEATURE_BL,
+   },
+   {
+   .name   = "m41t82",
+   .features   = M41T80_FEATURE_HT | M41T80_FEATURE_BL,
+   },
+   {
+   .name   = "m41t83",
+   .features   = M41T80_FEATURE_HT | M41T80_FEATURE_BL,
+   },
+   {
+   .name