Skip to contentSkip to conversation

add support for ST M41T94 SPI RTC

PATCH In review Kim B. Heino 3 participants 5 messages May 14, 2008 Real time clock (RTC)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 add support for ST M41T94 SPI RTC

This patch adds kernel driver for M41T94 RTC chip connected via SPI. I've tested it on two different AT91-based hardwares.

drivers/rtc/Kconfig +9 -0
diff -urN orig.full/drivers/rtc/Kconfig linux-2.6.25/drivers/rtc/Kconfig
@@ -266,6 +266,15 @@
 
 if SPI_MASTER
 
+config RTC_DRV_M41T94
+	tristate "ST M41T94"
+	help
+	  If you say yes here you will get support for the
+	  ST M41T94 SPI RTC chip.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called rtc-m41t94.
+
 config RTC_DRV_MAX6902
 	tristate "Maxim MAX6902"
 	help
drivers/rtc/Makefile +1 -0
diff -urN orig.full/drivers/rtc/Makefile linux-2.6.25/drivers/rtc/Makefile
@@ -33,6 +33,7 @@
 obj-$(CONFIG_RTC_DRV_EP93XX)	+= rtc-ep93xx.o
 obj-$(CONFIG_RTC_DRV_ISL1208)	+= rtc-isl1208.o
 obj-$(CONFIG_RTC_DRV_M41T80)	+= rtc-m41t80.o
+obj-$(CONFIG_RTC_DRV_M41T94)	+= rtc-m41t94.o
 obj-$(CONFIG_RTC_DRV_M48T59)	+= rtc-m48t59.o
 obj-$(CONFIG_RTC_DRV_M48T86)	+= rtc-m48t86.o
 obj-$(CONFIG_RTC_DRV_MAX6900)	+= rtc-max6900.o
drivers/rtc/rtc-m41t94.c +187 -0

187 lines not on this page · raw message

#1 lore raw
Quoted 3 lines · On Wed, 14 May 2008 15:19:37 +0300 "Kim B. Heino" <[email protected]>…

This patch adds kernel driver for M41T94 RTC chip connected via SPI. I've tested it on two different AT91-based hardwares.

Hi Kim,

just a few comments:

drivers/rtc/rtc-m41t94.c line 19

Quoted 10 lines
drivers/rtc/rtc-m41t94.c +10 -0
+
+#include <linux/module.h>
+#include <linux/version.h>
+
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <linux/init.h>
+#include <linux/rtc.h>
+#include <linux/spi/spi.h>
+#include <linux/bcd.h>

can you check that you really require
all of those #includes ?

drivers/rtc/rtc-m41t94.c line 36

Quoted 4 lines
drivers/rtc/rtc-m41t94.c +4 -0
+struct m41t94 {
+	struct rtc_device *rtc;
+	u8 buf[8]; /* Burst read cmd + 7 registers */
+};

why are you keeping the buffer here?

drivers/rtc/rtc-m41t94.c line 97

Quoted 9 lines
drivers/rtc/rtc-m41t94.c +9 -0
+
+	tm->tm_sec  = BCD2BIN(spi_w8r8(spi, M41T94_REG_SECONDS));
+	tm->tm_min  = BCD2BIN(spi_w8r8(spi, M41T94_REG_MINUTES));
+	tm->tm_hour = BCD2BIN(spi_w8r8(spi, M41T94_REG_HOURS));
+	tm->tm_wday = BCD2BIN(spi_w8r8(spi, M41T94_REG_WDAY)) - 1;
+	tm->tm_mday = BCD2BIN(spi_w8r8(spi, M41T94_REG_DAY));
+	tm->tm_mon  = BCD2BIN(spi_w8r8(spi, M41T94_REG_MONTH)) - 1;
+	/* assume 20YY not 19YY, and ignore century bit */
+	tm->tm_year = BCD2BIN(spi_w8r8(spi, M41T94_REG_YEAR)) + 100;

the choice is up to you, but I'd use the century bit if there is one.

drivers/rtc/rtc-m41t94.c line 187

Quoted 4 lines
drivers/rtc/rtc-m41t94.c +4 -0
+
+MODULE_AUTHOR ("Kim B. Heino <[email protected]>");
+MODULE_DESCRIPTION ("Driver for ST M41T94 SPI RTC");
+MODULE_LICENSE ("GPL");

no spaces between MODULE_XXX and the ( please.

Signature · 6 lines
 Best regards,

 Alessandro Zummo,
  Tower Technologies - Torino, Italy

  http://www.towertech.it
#2 lore raw

Hi Alessandro,

Quoted 2 lines

can you check that you really require
all of those #includes ?

You're right, I don't. Fixed.

Quoted 5 lines

drivers/rtc/rtc-m41t94.c line 36

Quoted 4 lines
drivers/rtc/rtc-m41t94.c +4 -0
+struct m41t94 {
+	struct rtc_device *rtc;
+	u8 buf[8]; /* Burst read cmd + 7 registers */
+};

why are you keeping the buffer here?

rtc-max6902.c did that too... Fixed.

Quoted 2 lines

the choice is up to you, but I'd use the century bit if there is one.

Ok, I'll add support for century bit. Again there are some other rtc-drivers (like rtc-m41t80.c and rtc-ds1307.c) not using it.

Quoted 1 line

no spaces between MODULE_XXX and the ( please.

Fixed.

I'll wait for more comments and post a new patch tomorrow.

#3 lore raw
Quoted 2 lines · Kim B. Heino

Ok, I'll add support for century bit. Again there are some other rtc-drivers (like rtc-m41t80.c and rtc-ds1307.c) not using it.

Oh, thanks for mentioning rtc-m41t80.c -- since I am currently fiddling
with it, it sounds like a good idea for an improvement. Thanks!

Maciej

#4 lore raw
In reply to Kim B. Heino
Quoted 9 lines · On Wed, 14 May 2008 17:23:35 +0300 "Kim B. Heino" <[email protected]>…
Quoted 7 lines

drivers/rtc/rtc-m41t94.c line 36

Quoted 6 lines
drivers/rtc/rtc-m41t94.c +4 -0
+struct m41t94 {
+	struct rtc_device *rtc;
+	u8 buf[8]; /* Burst read cmd + 7 registers */
+};

why are you keeping the buffer here?

rtc-max6902.c did that too... Fixed.

d'oh! I missed it. :)

Quoted 5 lines
Quoted 2 lines

the choice is up to you, but I'd use the century bit if there is one.

Ok, I'll add support for century bit. Again there are some other rtc-drivers (like rtc-m41t80.c and rtc-ds1307.c) not using it.

it's not mandatory, just a suggestion.

Quoted 2 lines

I'll wait for more comments and post a new patch tomorrow.

ok, thanks.

Signature · 6 lines
 Best regards,

 Alessandro Zummo,
  Tower Technologies - Torino, Italy

  http://www.towertech.it