diff mbox

[RFC] rtc: ds3234 fixes

Message ID 20081118142158.5948.41653.stgit@i1501.lan.towertech.it
State Superseded, archived
Headers show

Commit Message

Alessandro Zummo Nov. 18, 2008, 2:21 p.m. UTC
- no changelogs in code
- no banners
- use local buffers
- fix probe sequence

Signed-off-by: Alessandro Zummo <a.zummo@towertech.it>
Cc: Dennis Aberilla <denzzzhome@yahoo.com>
Cc: David Brownell <david-b@pacbell.net>
---

 drivers/rtc/rtc-ds3234.c |  101 +++++++++++++++-------------------------------
 1 files changed, 33 insertions(+), 68 deletions(-)



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
-~----------~----~----~----~------~----~------~--~---

Comments

David Brownell Nov. 18, 2008, 5:44 p.m. UTC | #1
On Tuesday 18 November 2008, Alessandro Zummo wrote:
> - use local buffers

Same comment:  buffers on stack are fine *IFF* you use the
call -- spi_write_then_read() -- which handles the DMA
safety issues for you.

- Dave


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
-~----------~----~----~----~------~----~------~--~---
diff mbox

Patch

diff --git a/drivers/rtc/rtc-ds3234.c b/drivers/rtc/rtc-ds3234.c
index 45e5b10..beb03ce 100644
--- a/drivers/rtc/rtc-ds3234.c
+++ b/drivers/rtc/rtc-ds3234.c
@@ -1,4 +1,4 @@ 
-/* drivers/rtc/rtc-ds3234.c
+/* rtc-ds3234.c
  *
  * Driver for Dallas Semiconductor (DS3234) SPI RTC with Integrated Crystal
  * and SRAM.
@@ -9,13 +9,10 @@ 
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  *
- * Changelog:
- *
- * 07-May-2008: Dennis Aberilla <denzzzhome@yahoo.com>
- *		- Created based on the max6902 code. Only implements the
- *		  date/time keeping functions; no SRAM yet.
  */
 
+#include <linux/init.h>
+#include <linux/module.h>
 #include <linux/device.h>
 #include <linux/platform_device.h>
 #include <linux/rtc.h>
@@ -36,13 +33,6 @@ 
 
 #undef DS3234_DEBUG
 
-struct ds3234 {
-	struct rtc_device *rtc;
-	u8 buf[8]; /* Burst read: addr + 7 regs */
-	u8 tx_buf[2];
-	u8 rx_buf[2];
-};
-
 static void ds3234_set_reg(struct device *dev, unsigned char address,
 				unsigned char data)
 {
@@ -60,10 +50,10 @@  static int ds3234_get_reg(struct device *dev, unsigned char address,
 				unsigned char *data)
 {
 	struct spi_device *spi = to_spi_device(dev);
-	struct ds3234 *chip = dev_get_drvdata(dev);
 	struct spi_message message;
 	struct spi_transfer xfer;
 	int status;
+	u8 buf[2];
 
 	if (!data)
 		return -EINVAL;
@@ -74,11 +64,11 @@  static int ds3234_get_reg(struct device *dev, unsigned char address,
 
 	/* Address + dummy tx byte */
 	xfer.len = 2;
-	xfer.tx_buf = chip->tx_buf;
-	xfer.rx_buf = chip->rx_buf;
+	xfer.tx_buf = &buf;
+	xfer.rx_buf = &buf;
 
-	chip->tx_buf[0] = address;
-	chip->tx_buf[1] = 0xff;
+	buf[0] = address;
+	buf[1] = 0xff;
 
 	spi_message_add_tail(&xfer, &message);
 
@@ -89,26 +79,26 @@  static int ds3234_get_reg(struct device *dev, unsigned char address,
 	else
 		return status;
 
-	*data = chip->rx_buf[1];
+	*data = buf[1];
 
 	return status;
 }
 
-static int ds3234_get_datetime(struct device *dev, struct rtc_time *dt)
+static int ds3234_read_time(struct device *dev, struct rtc_time *dt)
 {
 	struct spi_device *spi = to_spi_device(dev);
-	struct ds3234 *chip = dev_get_drvdata(dev);
 	struct spi_message message;
 	struct spi_transfer xfer;
 	int status;
+	u8 buf[8];
 
 	/* build the message */
 	spi_message_init(&message);
 	memset(&xfer, 0, sizeof(xfer));
 	xfer.len = 1 + 7;	/* Addr + 7 registers */
-	xfer.tx_buf = chip->buf;
-	xfer.rx_buf = chip->buf;
-	chip->buf[0] = 0x00;	/* Start address */
+	xfer.tx_buf = &buf;
+	xfer.rx_buf = &buf;
+	buf[0] = 0x00;	/* Start address */
 	spi_message_add_tail(&xfer, &message);
 
 	/* do the i/o */
@@ -119,13 +109,13 @@  static int ds3234_get_datetime(struct device *dev, struct rtc_time *dt)
 		return status;
 
 	/* Seconds, Minutes, Hours, Day, Date, Month, Year */
-	dt->tm_sec	= bcd2bin(chip->buf[1]);
-	dt->tm_min	= bcd2bin(chip->buf[2]);
-	dt->tm_hour	= bcd2bin(chip->buf[3] & 0x3f);
-	dt->tm_wday	= bcd2bin(chip->buf[4]) - 1; /* 0 = Sun */
-	dt->tm_mday	= bcd2bin(chip->buf[5]);
-	dt->tm_mon	= bcd2bin(chip->buf[6] & 0x1f) - 1; /* 0 = Jan */
-	dt->tm_year 	= bcd2bin(chip->buf[7] & 0xff) + 100; /* Assume 20YY */
+	dt->tm_sec	= bcd2bin(buf[1]);
+	dt->tm_min	= bcd2bin(buf[2]);
+	dt->tm_hour	= bcd2bin(buf[3] & 0x3f);
+	dt->tm_wday	= bcd2bin(buf[4]) - 1; /* 0 = Sun */
+	dt->tm_mday	= bcd2bin(buf[5]);
+	dt->tm_mon	= bcd2bin(buf[6] & 0x1f) - 1; /* 0 = Jan */
+	dt->tm_year 	= bcd2bin(buf[7] & 0xff) + 100; /* Assume 20YY */
 
 #ifdef DS3234_DEBUG
 	dev_dbg(dev, "\n%s : Read RTC values\n", __func__);
@@ -138,10 +128,10 @@  static int ds3234_get_datetime(struct device *dev, struct rtc_time *dt)
 	dev_dbg(dev, "tm_year: %i\n", dt->tm_year);
 #endif
 
-	return 0;
+	return rtc_valid_tm(dt);
 }
 
-static int ds3234_set_datetime(struct device *dev, struct rtc_time *dt)
+static int ds3234_set_time(struct device *dev, struct rtc_time *dt)
 {
 #ifdef DS3234_DEBUG
 	dev_dbg(dev, "\n%s : Setting RTC values\n", __func__);
@@ -174,16 +164,6 @@  static int ds3234_set_datetime(struct device *dev, struct rtc_time *dt)
 	return 0;
 }
 
-static int ds3234_read_time(struct device *dev, struct rtc_time *tm)
-{
-	return ds3234_get_datetime(dev, tm);
-}
-
-static int ds3234_set_time(struct device *dev, struct rtc_time *tm)
-{
-	return ds3234_set_datetime(dev, tm);
-}
-
 static const struct rtc_class_ops ds3234_rtc_ops = {
 	.read_time	= ds3234_read_time,
 	.set_time	= ds3234_set_time,
@@ -193,31 +173,15 @@  static int __devinit ds3234_probe(struct spi_device *spi)
 {
 	struct rtc_device *rtc;
 	unsigned char tmp;
-	struct ds3234 *chip;
 	int res;
 
-	rtc = rtc_device_register("ds3234",
-				&spi->dev, &ds3234_rtc_ops, THIS_MODULE);
-	if (IS_ERR(rtc))
-		return PTR_ERR(rtc);
-
 	spi->mode = SPI_MODE_3;
 	spi->bits_per_word = 8;
 	spi_setup(spi);
 
-	chip = kzalloc(sizeof(struct ds3234), GFP_KERNEL);
-	if (!chip) {
-		rtc_device_unregister(rtc);
-		return -ENOMEM;
-	}
-	chip->rtc = rtc;
-	dev_set_drvdata(&spi->dev, chip);
-
 	res = ds3234_get_reg(&spi->dev, DS3234_REG_SECONDS, &tmp);
-	if (res) {
-		rtc_device_unregister(rtc);
+	if (res != 0)
 		return res;
-	}
 
 	/* Control settings
 	 *
@@ -246,19 +210,21 @@  static int __devinit ds3234_probe(struct spi_device *spi)
 	ds3234_get_reg(&spi->dev, DS3234_REG_CONT_STAT, &tmp);
 	dev_info(&spi->dev, "Ctrl/Stat Reg: 0x%02x\n", tmp);
 
+	rtc = rtc_device_register("ds3234",
+				&spi->dev, &ds3234_rtc_ops, THIS_MODULE);
+	if (IS_ERR(rtc))
+		return PTR_ERR(rtc);
+
+	dev_set_drvdata(&spi->dev, rtc);
+
 	return 0;
 }
 
 static int __devexit ds3234_remove(struct spi_device *spi)
 {
-	struct ds3234 *chip = platform_get_drvdata(spi);
-	struct rtc_device *rtc = chip->rtc;
-
-	if (rtc)
-		rtc_device_unregister(rtc);
-
-	kfree(chip);
+	struct rtc_device *rtc = platform_get_drvdata(spi);
 
+	rtc_device_unregister(rtc);
 	return 0;
 }
 
@@ -274,7 +240,6 @@  static struct spi_driver ds3234_driver = {
 
 static __init int ds3234_init(void)
 {
-	printk(KERN_INFO "DS3234 SPI RTC Driver\n");
 	return spi_register_driver(&ds3234_driver);
 }
 module_init(ds3234_init);