13 #include <linux/module.h>
14 #include <linux/i2c.h>
16 #include <linux/rtc.h>
18 #define DRV_VERSION "0.3"
22 #define ISL1208_REG_SC 0x00
23 #define ISL1208_REG_MN 0x01
24 #define ISL1208_REG_HR 0x02
25 #define ISL1208_REG_HR_MIL (1<<7)
26 #define ISL1208_REG_HR_PM (1<<5)
27 #define ISL1208_REG_DT 0x03
28 #define ISL1208_REG_MO 0x04
29 #define ISL1208_REG_YR 0x05
30 #define ISL1208_REG_DW 0x06
31 #define ISL1208_RTC_SECTION_LEN 7
34 #define ISL1208_REG_SR 0x07
35 #define ISL1208_REG_SR_ARST (1<<7)
36 #define ISL1208_REG_SR_XTOSCB (1<<6)
37 #define ISL1208_REG_SR_WRTC (1<<4)
38 #define ISL1208_REG_SR_ALM (1<<2)
39 #define ISL1208_REG_SR_BAT (1<<1)
40 #define ISL1208_REG_SR_RTCF (1<<0)
41 #define ISL1208_REG_INT 0x08
42 #define ISL1208_REG_INT_ALME (1<<6)
43 #define ISL1208_REG_INT_IM (1<<7)
44 #define ISL1208_REG_09 0x09
45 #define ISL1208_REG_ATR 0x0a
46 #define ISL1208_REG_DTR 0x0b
49 #define ISL1208_REG_SCA 0x0c
50 #define ISL1208_REG_MNA 0x0d
51 #define ISL1208_REG_HRA 0x0e
52 #define ISL1208_REG_DTA 0x0f
53 #define ISL1208_REG_MOA 0x10
54 #define ISL1208_REG_DWA 0x11
55 #define ISL1208_ALARM_SECTION_LEN 6
58 #define ISL1208_REG_USR1 0x12
59 #define ISL1208_REG_USR2 0x13
60 #define ISL1208_USR_SECTION_LEN 2
96 isl1208_i2c_set_regs(
struct i2c_client *client,
u8 reg,
u8 const buf[],
113 memcpy(&i2c_buf[1], &buf[0], len);
123 isl1208_i2c_validate_client(
struct i2c_client *client)
127 0x80, 0x80, 0x40, 0xc0, 0xe0, 0x00, 0xf8
137 if (regs[i] & zero_mask[i])
155 isl1208_i2c_get_atr(
struct i2c_client *client)
180 isl1208_i2c_get_dtr(
struct i2c_client *client)
187 dtr = ((dtr & 0x3) * 20) * (dtr & (1 << 2) ? -1 : 1);
193 isl1208_i2c_get_usr(
struct i2c_client *client)
203 return (buf[1] << 8) | buf[0];
212 buf[1] = (usr >> 8) & 0xff;
224 dev_err(&client->
dev,
"%s: reading INT failed\n", __func__);
235 dev_err(&client->
dev,
"%s: writing INT failed\n", __func__);
246 int sr,
dtr, atr, usr;
248 sr = isl1208_i2c_get_sr(client);
250 dev_err(&client->
dev,
"%s: reading SR failed\n", __func__);
254 seq_printf(seq,
"status_reg\t:%s%s%s%s%s%s (0x%.2x)\n",
263 (sr & ISL1208_REG_SR_RTCF) ?
"bad" :
"okay");
265 dtr = isl1208_i2c_get_dtr(client);
267 seq_printf(seq,
"digital_trim\t: %d ppm\n", dtr);
269 atr = isl1208_i2c_get_atr(client);
271 seq_printf(seq,
"analog_trim\t: %d.%.2d pF\n",
272 atr >> 2, (atr & 0x3) * 25);
274 usr = isl1208_i2c_get_usr(client);
276 seq_printf(seq,
"user_data\t: 0x%.4x\n", usr);
287 sr = isl1208_i2c_get_sr(client);
289 dev_err(&client->
dev,
"%s: reading SR failed\n", __func__);
293 sr = isl1208_i2c_read_regs(client, 0, regs, ISL1208_RTC_SECTION_LEN);
295 dev_err(&client->
dev,
"%s: reading RTC section failed\n",
329 int icr,
yr, sr = isl1208_i2c_get_sr(client);
332 dev_err(&client->
dev,
"%s: reading SR failed\n", __func__);
339 dev_err(&client->
dev,
"%s: reading alarm section failed\n",
356 dev_err(&client->
dev,
"%s: reading RTC YR failed\n", __func__);
363 dev_err(&client->
dev,
"%s: reading INT failed\n", __func__);
377 unsigned long rtc_secs, alarm_secs;
381 err = isl1208_i2c_read_time(client, &rtc_tm);
392 if (!alarm->
enabled || alarm_secs <= rtc_secs)
408 err = isl1208_i2c_set_regs(client, offs, regs,
411 dev_err(&client->
dev,
"%s: writing ALARM section failed\n",
416 err = isl1208_rtc_toggle_alarm(client, enable);
452 sr = isl1208_i2c_get_sr(client);
454 dev_err(&client->
dev,
"%s: reading SR failed\n", __func__);
460 sr | ISL1208_REG_SR_WRTC);
462 dev_err(&client->
dev,
"%s: writing SR failed\n", __func__);
467 sr = isl1208_i2c_set_regs(client, 0, regs, ISL1208_RTC_SECTION_LEN);
469 dev_err(&client->
dev,
"%s: writing RTC section failed\n",
476 sr & ~ISL1208_REG_SR_WRTC);
478 dev_err(&client->
dev,
"%s: writing SR failed\n", __func__);
505 isl1208_rtc_interrupt(
int irq,
void *
data)
509 int handled = 0,
sr,
err;
517 sr = isl1208_i2c_get_sr(client);
522 dev_err(&client->
dev,
"%s: reading SR failed\n",
528 if (sr & ISL1208_REG_SR_ALM) {
532 sr &= ~ISL1208_REG_SR_ALM;
535 dev_err(&client->
dev,
"%s: writing SR failed\n",
541 err = isl1208_rtc_toggle_alarm(client, 0);
550 .proc = isl1208_rtc_proc,
551 .read_time = isl1208_rtc_read_time,
552 .set_time = isl1208_rtc_set_time,
553 .read_alarm = isl1208_rtc_read_alarm,
554 .set_alarm = isl1208_rtc_set_alarm,
560 isl1208_sysfs_show_atrim(
struct device *dev,
567 return sprintf(buf,
"%d.%.2d pF\n", atr >> 2, (atr & 0x3) * 25);
573 isl1208_sysfs_show_dtrim(
struct device *dev,
580 return sprintf(buf,
"%d ppm\n", dtr);
586 isl1208_sysfs_show_usr(
struct device *dev,
593 return sprintf(buf,
"0x%.4x\n", usr);
597 isl1208_sysfs_store_usr(
struct device *dev,
599 const char *buf,
size_t count)
603 if (buf[0] ==
'0' && (buf[1] ==
'x' || buf[1] ==
'X')) {
604 if (
sscanf(buf,
"%x", &usr) != 1)
607 if (
sscanf(buf,
"%d", &usr) != 1)
611 if (usr < 0 || usr > 0xffff)
618 isl1208_sysfs_store_usr);
620 static struct attribute *isl1208_rtc_attrs[] = {
621 &dev_attr_atrim.attr,
622 &dev_attr_dtrim.attr,
628 .attrs = isl1208_rtc_attrs,
640 if (isl1208_i2c_validate_client(client) < 0)
646 if (client->
irq > 0) {
648 isl1208_rtc_interrupt,
650 isl1208_driver.driver.name, client);
653 enable_irq_wake(client->
irq);
656 "Unable to request irq %d, no alarm support\n",
663 &client->
dev, &isl1208_rtc_ops,
670 i2c_set_clientdata(client, rtc);
672 rc = isl1208_i2c_get_sr(client);
674 dev_err(&client->
dev,
"reading status failed\n");
675 goto exit_unregister;
678 if (rc & ISL1208_REG_SR_RTCF)
679 dev_warn(&client->
dev,
"rtc power failure detected, "
680 "please set clock.\n");
684 goto exit_unregister;
700 struct rtc_device *rtc = i2c_get_clientdata(client);
719 .name =
"rtc-isl1208",
721 .probe = isl1208_probe,
722 .remove = isl1208_remove,
723 .id_table = isl1208_id,