diff mbox

RTC: add support for DS1388

Message ID 1238420501-16312-1-git-send-email-Joakim.Tjernlund@transmode.se
State Superseded, archived
Headers show

Commit Message

Joakim Tjernlund March 30, 2009, 1:41 p.m. UTC
Extend the ds1307 driver to support ds1388 too.

Signed-off-by: Joakim Tjernlund <Joakim.Tjernlund@transmode.se>
---
 drivers/rtc/rtc-ds1307.c |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

Comments

Alessandro Zummo March 30, 2009, 1:48 p.m. UTC | #1
On Mon, 30 Mar 2009 15:41:41 +0200
Joakim Tjernlund <Joakim.Tjernlund@transmode.se> wrote:

> +	case ds_1388:
> +		ds1307->reg_addr = 1; /* Seconds starts at 1 */
> +		break;

 what's the default for that var for the other chips?
Joakim Tjernlund March 30, 2009, 1:55 p.m. UTC | #2
Alessandro Zummo <alessandro.zummo@towertech.it> wrote on 30/03/2009 
15:48:30:

> On Mon, 30 Mar 2009 15:41:41 +0200
> Joakim Tjernlund <Joakim.Tjernlund@transmode.se> wrote:
> 
> > +   case ds_1388:
> > +      ds1307->reg_addr = 1; /* Seconds starts at 1 */
> > +      break;
> 
>  what's the default for that var for the other chips?

Zero, from:
        if (!(ds1307 = kzalloc(sizeof(struct ds1307), GFP_KERNEL)))
                return -ENOMEM;

--~--~---------~--~----~------------~-------~--~----~
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.
-~----------~----~----~----~------~----~------~--~---
Alessandro Zummo March 30, 2009, 2:54 p.m. UTC | #3
On Mon, 30 Mar 2009 15:55:27 +0200
Joakim Tjernlund <Joakim.Tjernlund@transmode.se> wrote:

> > 
> > > +   case ds_1388:
> > > +      ds1307->reg_addr = 1; /* Seconds starts at 1 */
> > > +      break;
> > 
> >  what's the default for that var for the other chips?
> 
> Zero, from:
>         if (!(ds1307 = kzalloc(sizeof(struct ds1307), GFP_KERNEL)))
>                 return -ENOMEM;

 I don't like it. It hides the logic behind an allocation
Joakim Tjernlund March 30, 2009, 4:05 p.m. UTC | #4
Alessandro Zummo <alessandro.zummo@towertech.it> wrote on 30/03/2009 
16:54:55:
> 
> On Mon, 30 Mar 2009 15:55:27 +0200
> Joakim Tjernlund <Joakim.Tjernlund@transmode.se> wrote:
> 
> > > 
> > > > +   case ds_1388:
> > > > +      ds1307->reg_addr = 1; /* Seconds starts at 1 */
> > > > +      break;
> > > 
> > >  what's the default for that var for the other chips?
> > 
> > Zero, from:
> >         if (!(ds1307 = kzalloc(sizeof(struct ds1307), GFP_KERNEL)))
> >                 return -ENOMEM;
> 
>  I don't like it. It hides the logic behind an allocation

eeh, lots of stuff in the kernel relies on such zeroing. What is
the purpose of kzalloc otherwise?
Even the rtc driver does so already(flags). Do you really
want me to add an explicit ds1307->reg_addr = 0 right after
kzalloc()?

 Jocke

--~--~---------~--~----~------------~-------~--~----~
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.
-~----------~----~----~----~------~----~------~--~---
Alessandro Zummo March 30, 2009, 4:16 p.m. UTC | #5
On Mon, 30 Mar 2009 18:05:49 +0200
Joakim Tjernlund <Joakim.Tjernlund@transmode.se> wrote:

> eeh, lots of stuff in the kernel relies on such zeroing. What is
> the purpose of kzalloc otherwise?
> Even the rtc driver does so already(flags). Do you really
> want me to add an explicit ds1307->reg_addr = 0 right after
> kzalloc()?

 wait, I see the current driver already has reg_addr. which
 kernel did you used to diff against?
diff mbox

Patch

diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index 7e5155e..8cda7dc 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -30,6 +30,7 @@  enum ds_type {
 	ds_1338,
 	ds_1339,
 	ds_1340,
+	ds_1388,
 	m41t00,
 	// rs5c372 too?  different address...
 };
@@ -86,6 +87,7 @@  enum ds_type {
 
 
 struct ds1307 {
+	u8			reg_addr;
 	u8			regs[11];
 	enum ds_type		type;
 	unsigned long		flags;
@@ -124,6 +126,7 @@  static const struct i2c_device_id ds1307_id[] = {
 	{ "ds1337", ds_1337 },
 	{ "ds1338", ds_1338 },
 	{ "ds1339", ds_1339 },
+	{ "ds1388", ds_1388 },
 	{ "ds1340", ds_1340 },
 	{ "m41t00", m41t00 },
 	{ }
@@ -202,8 +205,8 @@  static int ds1307_get_time(struct device *dev, struct rtc_time *t)
 	int		tmp;
 
 	/* read the RTC date and time registers all at once */
-	tmp = i2c_smbus_read_i2c_block_data(ds1307->client,
-		DS1307_REG_SECS, 7, ds1307->regs);
+	tmp = i2c_smbus_read_i2c_block_data(ds1307->client, ds1307->reg_addr,
+					    7, ds1307->regs);
 	if (tmp != 7) {
 		dev_err(dev, "%s error %d\n", "read", tmp);
 		return -EIO;
@@ -279,7 +282,8 @@  static int ds1307_set_time(struct device *dev, struct rtc_time *t)
 		"write", buf[0], buf[1], buf[2], buf[3],
 		buf[4], buf[5], buf[6]);
 
-	result = i2c_smbus_write_i2c_block_data(ds1307->client, 0, 7, buf);
+	result = i2c_smbus_write_i2c_block_data(ds1307->client,
+						ds1307->reg_addr, 7, buf);
 	if (result < 0) {
 		dev_err(dev, "%s error %d\n", "write", result);
 		return result;
@@ -589,6 +593,9 @@  static int __devinit ds1307_probe(struct i2c_client *client,
 			dev_warn(&client->dev, "SET TIME!\n");
 		}
 		break;
+	case ds_1388:
+		ds1307->reg_addr = 1; /* Seconds starts at 1 */
+		break;
 	default:
 		break;
 	}
@@ -651,6 +658,7 @@  read_rtc:
 		break;
 	case ds_1337:
 	case ds_1339:
+	case ds_1388:
 		break;
 	}