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

2007-06-28 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]>
Acked-by: Alessandro Zummo <[EMAIL PROTECTED]>
---
Changes from previous version (take 2):

* Fix wrong static storage class (by Andrew Morton)
* Move a Kconfig entry into "I2C RTC drivers" section

 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..661386f 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -213,6 +213,18 @@ config RTC_DRV_PCF8583
  This driver can also be built as a module. If so, the module
  will be called rtc-pcf8583.
 
+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.
+
 comment "SPI RTC drivers"
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..4875a44
--- /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  

Re: [PATCH 1/2] rtc: add rtc-m41t80 driver

2007-06-28 Thread Atsushi Nemoto
On Mon, 25 Jun 2007 22:21:42 -0700, Andrew Morton <[EMAIL PROTECTED]> wrote:
> > Oh the variable should not be static!
> > I will send updated patch.
> 
> I'll fix it up.
...
> > Are you going back to "take 1" patches?  Why?
> 
> Stupidity, apparently.  Will restore the take2 patches.

Thanks.  I found another problem with these patches: I inserted
Kconfig entries at wrong place.  I will send take3 patches including
your fix.

---
Atsushi Nemoto
-
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/


Re: [PATCH 1/2] rtc: add rtc-m41t80 driver

2007-06-28 Thread Atsushi Nemoto
On Mon, 25 Jun 2007 22:21:42 -0700, Andrew Morton [EMAIL PROTECTED] wrote:
  Oh the variable should not be static!
  I will send updated patch.
 
 I'll fix it up.
...
  Are you going back to take 1 patches?  Why?
 
 Stupidity, apparently.  Will restore the take2 patches.

Thanks.  I found another problem with these patches: I inserted
Kconfig entries at wrong place.  I will send take3 patches including
your fix.

---
Atsushi Nemoto
-
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 3)

2007-06-28 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]
Acked-by: Alessandro Zummo [EMAIL PROTECTED]
---
Changes from previous version (take 2):

* Fix wrong static storage class (by Andrew Morton)
* Move a Kconfig entry into I2C RTC drivers section

 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..661386f 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -213,6 +213,18 @@ config RTC_DRV_PCF8583
  This driver can also be built as a module. If so, the module
  will be called rtc-pcf8583.
 
+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.
+
 comment SPI RTC drivers
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..4875a44
--- /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 linux/module.h
+#include linux/init.h
+#include linux/slab.h
+#include linux/string.h
+#include linux/i2c.h
+#include linux/rtc.h
+#include linux/bcd.h
+
+#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,
+   

Re: [PATCH 1/2] rtc: add rtc-m41t80 driver

2007-06-25 Thread Andrew Morton
On Tue, 26 Jun 2007 14:15:36 +0900 (JST) Atsushi Nemoto <[EMAIL PROTECTED]> 
wrote:

> On Mon, 25 Jun 2007 21:46:20 -0700, Andrew Morton <[EMAIL PROTECTED]> wrote:
> > > + const static struct m41t80_chip_info *chip;
> > 
> > It's a bit weird that `chip' has static storage class here.  Was that
> > deliberate?
> 
> Oh the variable should not be static!
> I will send updated patch.

I'll fix it up.

> BTW, I reveived following mails:
> 
> Subject: - rtc-watchdog-support-for-rtc-m41t80-driver-take-2.patch removed 
> from -mm tree
> Subject: - rtc-add-rtc-m41t80-driver-take-2.patch removed from -mm tree
> Subject: + rtc-add-rtc-m41t80-driver.patch added to -mm tree
> Subject: + rtc-watchdog-support-for-rtc-m41t80-driver.patch added to -mm tree
> 
> Are you going back to "take 1" patches?  Why?

Stupidity, apparently.  Will restore the take2 patches.
-
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/


Re: [PATCH 1/2] rtc: add rtc-m41t80 driver

2007-06-25 Thread Atsushi Nemoto
On Mon, 25 Jun 2007 21:46:20 -0700, Andrew Morton <[EMAIL PROTECTED]> wrote:
> > +   const static struct m41t80_chip_info *chip;
> 
> It's a bit weird that `chip' has static storage class here.  Was that
> deliberate?

Oh the variable should not be static!
I will send updated patch.

BTW, I reveived following mails:

Subject: - rtc-watchdog-support-for-rtc-m41t80-driver-take-2.patch removed from 
-mm tree
Subject: - rtc-add-rtc-m41t80-driver-take-2.patch removed from -mm tree
Subject: + rtc-add-rtc-m41t80-driver.patch added to -mm tree
Subject: + rtc-watchdog-support-for-rtc-m41t80-driver.patch added to -mm tree

Are you going back to "take 1" patches?  Why?

---
Atsushi Nemoto
-
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/


Re: [PATCH 1/2] rtc: add rtc-m41t80 driver

2007-06-25 Thread Andrew Morton
On Thu, 21 Jun 2007 02:09:34 +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]>
>
> ...
>
> +static int m41t80_probe(struct i2c_client *client)
> +{
> + int i, rc = 0;
> + struct rtc_device *rtc = NULL;
> + struct rtc_time tm;
> + struct m41t80_platform_data *pdata = client->dev.platform_data;
> + const static struct m41t80_chip_info *chip;

It's a bit weird that `chip' has static storage class here.  Was that
deliberate?


> + struct m41t80_data *clientdata = NULL;
> +
> + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C
> +  | I2C_FUNC_SMBUS_BYTE_DATA)) {
> + rc = -ENODEV;
> + goto exit;
> + }
> +
> + dev_info(>dev,
> +  "chip found, driver version " DRV_VERSION "\n");
> +
> + chip = NULL;
> + for (i = 0; i < ARRAY_SIZE(m41t80_chip_info_tbl); i++) {
> + if (!strcmp(m41t80_chip_info_tbl[i].name, client->name)) {
> + chip = _chip_info_tbl[i];
> + break;
> + }
> + }
> + if (!chip) {
> + dev_err(>dev, "%s is not supported\n", client->name);
> + rc = -ENODEV;
> + goto exit;
> + }
> +
> + clientdata = kzalloc(sizeof(*clientdata), GFP_KERNEL);
> + if (!clientdata) {
> + rc = -ENOMEM;
> + goto exit;
> + }
> +
> + rtc = rtc_device_register(client->name, >dev,
> +   _rtc_ops, THIS_MODULE);
> + if (IS_ERR(rtc)) {
> + rc = PTR_ERR(rtc);
> + rtc = NULL;
> + goto exit;
> + }
> +
> + clientdata->rtc = rtc;
> + clientdata->chip = chip;
> + i2c_set_clientdata(client, clientdata);
> +
> + /* If asked, disable SQW, set SQW frequency & re-enable */
> + if (pdata && pdata->sqw_freq) {
> + rc = i2c_smbus_read_byte_data(client, M41T80_REG_ALARM_MON);
> + if (rc < 0)
> + goto sqw_err;
> + if (i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_MON,
> +   rc & ~0x40) < 0 ||
> + i2c_smbus_write_byte_data(client, M41T80_REG_SQW,
> +   pdata->sqw_freq) < 0 ||
> + i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_MON,
> +   rc | 0x40) < 0)
> + goto sqw_err;
> + }
> +
> + /* Make sure HT (Halt Update) bit is cleared */
> + rc = i2c_smbus_read_byte_data(client, M41T80_REG_ALARM_HOUR);
> + if (rc < 0)
> + goto ht_err;
> +
> + if (rc & M41T80_ALHOUR_HT) {
> + if (chip->features & M41T80_FEATURE_HT) {
> + m41t80_get_datetime(client, );
> + dev_info(>dev, "HT bit was set!\n");
> + dev_info(>dev,
> +  "Power Down at "
> +  "%04i-%02i-%02i %02i:%02i:%02i\n",
> +  tm.tm_year + 1900,
> +  tm.tm_mon + 1, tm.tm_mday, tm.tm_hour,
> +  tm.tm_min, tm.tm_sec);
> + }
> + if (i2c_smbus_write_byte_data(client,
> +   M41T80_REG_ALARM_HOUR,
> +   rc & ~M41T80_ALHOUR_HT) < 0)
> + goto ht_err;
> + }
> +
> + /* Make sure ST (stop) bit is cleared */
> + rc = i2c_smbus_read_byte_data(client, M41T80_REG_SEC);
> + if (rc < 0)
> + goto st_err;
> +
> + if (rc & M41T80_SEC_ST) {
> + if (i2c_smbus_write_byte_data(client, M41T80_REG_SEC,
> +   rc & ~M41T80_SEC_ST) < 0)
> + goto st_err;
> + }
> +
> + rc = m41t80_sysfs_register(>dev);
> + if (rc)
> + goto exit;
> +
> + return 0;
> +
> +st_err:
> + rc = -EIO;
> + dev_err(>dev, "Can't clear ST bit\n");
> + goto exit;
> +ht_err:
> + rc = -EIO;
> + dev_err(>dev, "Can't clear HT bit\n");
> + goto exit;
> +sqw_err:
> + rc = -EIO;
> + dev_err(>dev, "Can't set SQW Frequency\n");
> +
> +exit:
> + if (rtc)
> + rtc_device_unregister(rtc);
> + kfree(clientdata);
> + return rc;
> +}

-
To unsubscribe from 

Re: [PATCH 1/2] rtc: add rtc-m41t80 driver

2007-06-25 Thread Andrew Morton
On Thu, 21 Jun 2007 02:09:34 +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]

 ...

 +static int m41t80_probe(struct i2c_client *client)
 +{
 + int i, rc = 0;
 + struct rtc_device *rtc = NULL;
 + struct rtc_time tm;
 + struct m41t80_platform_data *pdata = client-dev.platform_data;
 + const static struct m41t80_chip_info *chip;

It's a bit weird that `chip' has static storage class here.  Was that
deliberate?


 + struct m41t80_data *clientdata = NULL;
 +
 + if (!i2c_check_functionality(client-adapter, I2C_FUNC_I2C
 +  | I2C_FUNC_SMBUS_BYTE_DATA)) {
 + rc = -ENODEV;
 + goto exit;
 + }
 +
 + dev_info(client-dev,
 +  chip found, driver version  DRV_VERSION \n);
 +
 + chip = NULL;
 + for (i = 0; i  ARRAY_SIZE(m41t80_chip_info_tbl); i++) {
 + if (!strcmp(m41t80_chip_info_tbl[i].name, client-name)) {
 + chip = m41t80_chip_info_tbl[i];
 + break;
 + }
 + }
 + if (!chip) {
 + dev_err(client-dev, %s is not supported\n, client-name);
 + rc = -ENODEV;
 + goto exit;
 + }
 +
 + clientdata = kzalloc(sizeof(*clientdata), GFP_KERNEL);
 + if (!clientdata) {
 + rc = -ENOMEM;
 + goto exit;
 + }
 +
 + rtc = rtc_device_register(client-name, client-dev,
 +   m41t80_rtc_ops, THIS_MODULE);
 + if (IS_ERR(rtc)) {
 + rc = PTR_ERR(rtc);
 + rtc = NULL;
 + goto exit;
 + }
 +
 + clientdata-rtc = rtc;
 + clientdata-chip = chip;
 + i2c_set_clientdata(client, clientdata);
 +
 + /* If asked, disable SQW, set SQW frequency  re-enable */
 + if (pdata  pdata-sqw_freq) {
 + rc = i2c_smbus_read_byte_data(client, M41T80_REG_ALARM_MON);
 + if (rc  0)
 + goto sqw_err;
 + if (i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_MON,
 +   rc  ~0x40)  0 ||
 + i2c_smbus_write_byte_data(client, M41T80_REG_SQW,
 +   pdata-sqw_freq)  0 ||
 + i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_MON,
 +   rc | 0x40)  0)
 + goto sqw_err;
 + }
 +
 + /* Make sure HT (Halt Update) bit is cleared */
 + rc = i2c_smbus_read_byte_data(client, M41T80_REG_ALARM_HOUR);
 + if (rc  0)
 + goto ht_err;
 +
 + if (rc  M41T80_ALHOUR_HT) {
 + if (chip-features  M41T80_FEATURE_HT) {
 + m41t80_get_datetime(client, tm);
 + dev_info(client-dev, HT bit was set!\n);
 + dev_info(client-dev,
 +  Power Down at 
 +  %04i-%02i-%02i %02i:%02i:%02i\n,
 +  tm.tm_year + 1900,
 +  tm.tm_mon + 1, tm.tm_mday, tm.tm_hour,
 +  tm.tm_min, tm.tm_sec);
 + }
 + if (i2c_smbus_write_byte_data(client,
 +   M41T80_REG_ALARM_HOUR,
 +   rc  ~M41T80_ALHOUR_HT)  0)
 + goto ht_err;
 + }
 +
 + /* Make sure ST (stop) bit is cleared */
 + rc = i2c_smbus_read_byte_data(client, M41T80_REG_SEC);
 + if (rc  0)
 + goto st_err;
 +
 + if (rc  M41T80_SEC_ST) {
 + if (i2c_smbus_write_byte_data(client, M41T80_REG_SEC,
 +   rc  ~M41T80_SEC_ST)  0)
 + goto st_err;
 + }
 +
 + rc = m41t80_sysfs_register(client-dev);
 + if (rc)
 + goto exit;
 +
 + return 0;
 +
 +st_err:
 + rc = -EIO;
 + dev_err(client-dev, Can't clear ST bit\n);
 + goto exit;
 +ht_err:
 + rc = -EIO;
 + dev_err(client-dev, Can't clear HT bit\n);
 + goto exit;
 +sqw_err:
 + rc = -EIO;
 + dev_err(client-dev, Can't set SQW Frequency\n);
 +
 +exit:
 + if (rtc)
 + rtc_device_unregister(rtc);
 + kfree(clientdata);
 + return rc;
 +}

-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  

Re: [PATCH 1/2] rtc: add rtc-m41t80 driver

2007-06-25 Thread Atsushi Nemoto
On Mon, 25 Jun 2007 21:46:20 -0700, Andrew Morton [EMAIL PROTECTED] wrote:
  +   const static struct m41t80_chip_info *chip;
 
 It's a bit weird that `chip' has static storage class here.  Was that
 deliberate?

Oh the variable should not be static!
I will send updated patch.

BTW, I reveived following mails:

Subject: - rtc-watchdog-support-for-rtc-m41t80-driver-take-2.patch removed from 
-mm tree
Subject: - rtc-add-rtc-m41t80-driver-take-2.patch removed from -mm tree
Subject: + rtc-add-rtc-m41t80-driver.patch added to -mm tree
Subject: + rtc-watchdog-support-for-rtc-m41t80-driver.patch added to -mm tree

Are you going back to take 1 patches?  Why?

---
Atsushi Nemoto
-
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/


Re: [PATCH 1/2] rtc: add rtc-m41t80 driver

2007-06-25 Thread Andrew Morton
On Tue, 26 Jun 2007 14:15:36 +0900 (JST) Atsushi Nemoto [EMAIL PROTECTED] 
wrote:

 On Mon, 25 Jun 2007 21:46:20 -0700, Andrew Morton [EMAIL PROTECTED] wrote:
   + const static struct m41t80_chip_info *chip;
  
  It's a bit weird that `chip' has static storage class here.  Was that
  deliberate?
 
 Oh the variable should not be static!
 I will send updated patch.

I'll fix it up.

 BTW, I reveived following mails:
 
 Subject: - rtc-watchdog-support-for-rtc-m41t80-driver-take-2.patch removed 
 from -mm tree
 Subject: - rtc-add-rtc-m41t80-driver-take-2.patch removed from -mm tree
 Subject: + rtc-add-rtc-m41t80-driver.patch added to -mm tree
 Subject: + rtc-watchdog-support-for-rtc-m41t80-driver.patch added to -mm tree
 
 Are you going back to take 1 patches?  Why?

Stupidity, apparently.  Will restore the take2 patches.
-
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/


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   

[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 linux/module.h
+#include linux/init.h
+#include linux/slab.h
+#include linux/string.h
+#include linux/i2c.h
+#include linux/rtc.h
+#include linux/bcd.h
+
+#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,
+   },

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

2007-06-20 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 (rtc-m41t8xx.c):

* Change the name. (rtc-m41txx to rtc-m41t80)
* Enumerate more chip names which seems to be supported.
* Basic alarm support.  (IRQ support is not implemented yet)
* Define M41T80_DATETIME_REG_SIZE for size of read/write buffer.
* Add "flags" attribute (including battery status bit) to sysfs.

 drivers/rtc/Kconfig  |   12 +
 drivers/rtc/Makefile |1 +
 drivers/rtc/rtc-m41t80.c |  578 ++
 include/linux/m41t80.h   |   40 
 4 files changed, 631 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..cc773ad
--- /dev/null
+++ b/drivers/rtc/rtc-m41t80.c
@@ -0,0 +1,578 @@
+/*
+ * 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 
+#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_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.04"
+
+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,
+   },
+   {
+  

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

2007-06-20 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 (rtc-m41t8xx.c):

* Change the name. (rtc-m41txx to rtc-m41t80)
* Enumerate more chip names which seems to be supported.
* Basic alarm support.  (IRQ support is not implemented yet)
* Define M41T80_DATETIME_REG_SIZE for size of read/write buffer.
* Add flags attribute (including battery status bit) to sysfs.

 drivers/rtc/Kconfig  |   12 +
 drivers/rtc/Makefile |1 +
 drivers/rtc/rtc-m41t80.c |  578 ++
 include/linux/m41t80.h   |   40 
 4 files changed, 631 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..cc773ad
--- /dev/null
+++ b/drivers/rtc/rtc-m41t80.c
@@ -0,0 +1,578 @@
+/*
+ * 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 linux/module.h
+#include linux/init.h
+#include linux/slab.h
+#include linux/string.h
+#include linux/i2c.h
+#include linux/rtc.h
+#include linux/bcd.h
+#include linux/m41t80.h
+
+#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_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.04
+
+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   =