aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc/rtc-ds1307.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/rtc/rtc-ds1307.c')
-rw-r--r--drivers/rtc/rtc-ds1307.c62
1 files changed, 20 insertions, 42 deletions
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index d827ce570a8c..b2005b44e4f7 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -106,9 +106,9 @@ struct ds1307 {
106 struct i2c_client *client; 106 struct i2c_client *client;
107 struct rtc_device *rtc; 107 struct rtc_device *rtc;
108 struct work_struct work; 108 struct work_struct work;
109 s32 (*read_block_data)(struct i2c_client *client, u8 command, 109 s32 (*read_block_data)(const struct i2c_client *client, u8 command,
110 u8 length, u8 *values); 110 u8 length, u8 *values);
111 s32 (*write_block_data)(struct i2c_client *client, u8 command, 111 s32 (*write_block_data)(const struct i2c_client *client, u8 command,
112 u8 length, const u8 *values); 112 u8 length, const u8 *values);
113}; 113};
114 114
@@ -149,6 +149,7 @@ static const struct i2c_device_id ds1307_id[] = {
149 { "ds1340", ds_1340 }, 149 { "ds1340", ds_1340 },
150 { "ds3231", ds_3231 }, 150 { "ds3231", ds_3231 },
151 { "m41t00", m41t00 }, 151 { "m41t00", m41t00 },
152 { "pt7c4338", ds_1307 },
152 { "rx8025", rx_8025 }, 153 { "rx8025", rx_8025 },
153 { } 154 { }
154}; 155};
@@ -158,8 +159,8 @@ MODULE_DEVICE_TABLE(i2c, ds1307_id);
158 159
159#define BLOCK_DATA_MAX_TRIES 10 160#define BLOCK_DATA_MAX_TRIES 10
160 161
161static s32 ds1307_read_block_data_once(struct i2c_client *client, u8 command, 162static s32 ds1307_read_block_data_once(const struct i2c_client *client,
162 u8 length, u8 *values) 163 u8 command, u8 length, u8 *values)
163{ 164{
164 s32 i, data; 165 s32 i, data;
165 166
@@ -172,7 +173,7 @@ static s32 ds1307_read_block_data_once(struct i2c_client *client, u8 command,
172 return i; 173 return i;
173} 174}
174 175
175static s32 ds1307_read_block_data(struct i2c_client *client, u8 command, 176static s32 ds1307_read_block_data(const struct i2c_client *client, u8 command,
176 u8 length, u8 *values) 177 u8 length, u8 *values)
177{ 178{
178 u8 oldvalues[I2C_SMBUS_BLOCK_MAX]; 179 u8 oldvalues[I2C_SMBUS_BLOCK_MAX];
@@ -198,7 +199,7 @@ static s32 ds1307_read_block_data(struct i2c_client *client, u8 command,
198 return length; 199 return length;
199} 200}
200 201
201static s32 ds1307_write_block_data(struct i2c_client *client, u8 command, 202static s32 ds1307_write_block_data(const struct i2c_client *client, u8 command,
202 u8 length, const u8 *values) 203 u8 length, const u8 *values)
203{ 204{
204 u8 currvalues[I2C_SMBUS_BLOCK_MAX]; 205 u8 currvalues[I2C_SMBUS_BLOCK_MAX];
@@ -495,50 +496,27 @@ static int ds1337_set_alarm(struct device *dev, struct rtc_wkalrm *t)
495 return 0; 496 return 0;
496} 497}
497 498
498static int ds1307_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) 499static int ds1307_alarm_irq_enable(struct device *dev, unsigned int enabled)
499{ 500{
500 struct i2c_client *client = to_i2c_client(dev); 501 struct i2c_client *client = to_i2c_client(dev);
501 struct ds1307 *ds1307 = i2c_get_clientdata(client); 502 struct ds1307 *ds1307 = i2c_get_clientdata(client);
502 int ret; 503 int ret;
503 504
504 switch (cmd) { 505 if (!test_bit(HAS_ALARM, &ds1307->flags))
505 case RTC_AIE_OFF: 506 return -ENOTTY;
506 if (!test_bit(HAS_ALARM, &ds1307->flags))
507 return -ENOTTY;
508
509 ret = i2c_smbus_read_byte_data(client, DS1337_REG_CONTROL);
510 if (ret < 0)
511 return ret;
512
513 ret &= ~DS1337_BIT_A1IE;
514
515 ret = i2c_smbus_write_byte_data(client,
516 DS1337_REG_CONTROL, ret);
517 if (ret < 0)
518 return ret;
519
520 break;
521
522 case RTC_AIE_ON:
523 if (!test_bit(HAS_ALARM, &ds1307->flags))
524 return -ENOTTY;
525 507
526 ret = i2c_smbus_read_byte_data(client, DS1337_REG_CONTROL); 508 ret = i2c_smbus_read_byte_data(client, DS1337_REG_CONTROL);
527 if (ret < 0) 509 if (ret < 0)
528 return ret; 510 return ret;
529 511
512 if (enabled)
530 ret |= DS1337_BIT_A1IE; 513 ret |= DS1337_BIT_A1IE;
514 else
515 ret &= ~DS1337_BIT_A1IE;
531 516
532 ret = i2c_smbus_write_byte_data(client, 517 ret = i2c_smbus_write_byte_data(client, DS1337_REG_CONTROL, ret);
533 DS1337_REG_CONTROL, ret); 518 if (ret < 0)
534 if (ret < 0) 519 return ret;
535 return ret;
536
537 break;
538
539 default:
540 return -ENOIOCTLCMD;
541 }
542 520
543 return 0; 521 return 0;
544} 522}
@@ -548,7 +526,7 @@ static const struct rtc_class_ops ds13xx_rtc_ops = {
548 .set_time = ds1307_set_time, 526 .set_time = ds1307_set_time,
549 .read_alarm = ds1337_read_alarm, 527 .read_alarm = ds1337_read_alarm,
550 .set_alarm = ds1337_set_alarm, 528 .set_alarm = ds1337_set_alarm,
551 .ioctl = ds1307_ioctl, 529 .alarm_irq_enable = ds1307_alarm_irq_enable,
552}; 530};
553 531
554/*----------------------------------------------------------------------*/ 532/*----------------------------------------------------------------------*/