18 #include <linux/kernel.h>
19 #include <linux/module.h>
21 #include <linux/i2c.h>
22 #include <linux/rtc.h>
25 #include <linux/slab.h>
27 #define DS3232_REG_SECONDS 0x00
28 #define DS3232_REG_MINUTES 0x01
29 #define DS3232_REG_HOURS 0x02
30 #define DS3232_REG_AMPM 0x02
31 #define DS3232_REG_DAY 0x03
32 #define DS3232_REG_DATE 0x04
33 #define DS3232_REG_MONTH 0x05
34 #define DS3232_REG_CENTURY 0x05
35 #define DS3232_REG_YEAR 0x06
36 #define DS3232_REG_ALARM1 0x07
37 #define DS3232_REG_ALARM2 0x0B
38 #define DS3232_REG_CR 0x0E
39 # define DS3232_REG_CR_nEOSC 0x80
40 # define DS3232_REG_CR_INTCN 0x04
41 # define DS3232_REG_CR_A2IE 0x02
42 # define DS3232_REG_CR_A1IE 0x01
44 #define DS3232_REG_SR 0x0F
45 # define DS3232_REG_SR_OSF 0x80
46 # define DS3232_REG_SR_BSY 0x04
47 # define DS3232_REG_SR_A2F 0x02
48 # define DS3232_REG_SR_A1F 0x01
76 "oscillator discontinuity flagged, "
106 unsigned int week, twelve_hr, am_pm;
107 unsigned int century, add_century = 0;
126 twelve_hr = hour & 0x40;
128 century = month & 0x80;
157 static int ds3232_set_time(
struct device *dev,
struct rtc_time *time)
215 alarm->
time.tm_mon = -1;
216 alarm->
time.tm_year = -1;
217 alarm->
time.tm_wday = -1;
218 alarm->
time.tm_yday = -1;
219 alarm->
time.tm_isdst = -1;
237 struct ds3232 *ds3232 = i2c_get_clientdata(client);
242 if (client->
irq <= 0)
283 static void ds3232_update_alarm(
struct i2c_client *client)
285 struct ds3232 *ds3232 = i2c_get_clientdata(client);
325 static int ds3232_alarm_irq_enable(
struct device *dev,
unsigned int enabled)
328 struct ds3232 *ds3232 = i2c_get_clientdata(client);
330 if (client->
irq <= 0)
338 ds3232_update_alarm(client);
345 struct ds3232 *ds3232 = i2c_get_clientdata(client);
354 struct ds3232 *ds3232 =
container_of(work,
struct ds3232, work);
373 stat &= ~DS3232_REG_SR_A1F;
387 .read_time = ds3232_read_time,
388 .set_time = ds3232_set_time,
389 .read_alarm = ds3232_read_alarm,
390 .set_alarm = ds3232_set_alarm,
391 .alarm_irq_enable = ds3232_alarm_irq_enable,
397 struct ds3232 *ds3232;
400 ds3232 = kzalloc(
sizeof(
struct ds3232),
GFP_KERNEL);
405 i2c_set_clientdata(client, ds3232);
410 ret = ds3232_check_rtc_status(client);
416 if (IS_ERR(ds3232->
rtc)) {
417 ret = PTR_ERR(ds3232->
rtc);
418 dev_err(&client->
dev,
"unable to register the class device\n");
422 if (client->
irq >= 0) {
426 dev_err(&client->
dev,
"unable to request IRQ\n");
434 if (client->
irq >= 0)
444 struct ds3232 *ds3232 = i2c_get_clientdata(client);
446 if (client->
irq >= 0) {
468 .name =
"rtc-ds3232",
471 .probe = ds3232_probe,
473 .id_table = ds3232_id,