]>
git.ipfire.org Git - people/ms/u-boot.git/blob - drivers/rtc/isl1208.c
3 * Tor Krill, Excito Elektronik i Skåne , tor@excito.com
5 * Modelled after the ds1337 driver
7 * SPDX-License-Identifier: GPL-2.0+
11 * Date & Time support (no alarms) for Intersil
12 * ISL1208 Real Time Clock (RTC).
20 /*---------------------------------------------------------------------*/
22 #define DEBUGR(fmt,args...) printf(fmt ,##args)
24 #define DEBUGR(fmt,args...)
26 /*---------------------------------------------------------------------*/
29 * RTC register addresses
32 #define RTC_SEC_REG_ADDR 0x0
33 #define RTC_MIN_REG_ADDR 0x1
34 #define RTC_HR_REG_ADDR 0x2
35 #define RTC_DATE_REG_ADDR 0x3
36 #define RTC_MON_REG_ADDR 0x4
37 #define RTC_YR_REG_ADDR 0x5
38 #define RTC_DAY_REG_ADDR 0x6
39 #define RTC_STAT_REG_ADDR 0x7
41 * RTC control register bits
45 * RTC status register bits
47 #define RTC_STAT_BIT_ARST 0x80 /* AUTO RESET ENABLE BIT */
48 #define RTC_STAT_BIT_XTOSCB 0x40 /* CRYSTAL OSCILLATOR ENABLE BIT */
49 #define RTC_STAT_BIT_WRTC 0x10 /* WRITE RTC ENABLE BIT */
50 #define RTC_STAT_BIT_ALM 0x04 /* ALARM BIT */
51 #define RTC_STAT_BIT_BAT 0x02 /* BATTERY BIT */
52 #define RTC_STAT_BIT_RTCF 0x01 /* REAL TIME CLOCK FAIL BIT */
54 static uchar
rtc_read (uchar reg
);
55 static void rtc_write (uchar reg
, uchar val
);
58 * Get the current time from the RTC
61 int rtc_get (struct rtc_time
*tmp
)
64 uchar sec
, min
, hour
, mday
, wday
, mon
, year
, status
;
66 status
= rtc_read (RTC_STAT_REG_ADDR
);
67 sec
= rtc_read (RTC_SEC_REG_ADDR
);
68 min
= rtc_read (RTC_MIN_REG_ADDR
);
69 hour
= rtc_read (RTC_HR_REG_ADDR
);
70 wday
= rtc_read (RTC_DAY_REG_ADDR
);
71 mday
= rtc_read (RTC_DATE_REG_ADDR
);
72 mon
= rtc_read (RTC_MON_REG_ADDR
);
73 year
= rtc_read (RTC_YR_REG_ADDR
);
75 DEBUGR ("Get RTC year: %02x mon: %02x mday: %02x wday: %02x "
76 "hr: %02x min: %02x sec: %02x status: %02x\n",
77 year
, mon
, mday
, wday
, hour
, min
, sec
, status
);
79 if (status
& RTC_STAT_BIT_RTCF
) {
80 printf ("### Warning: RTC oscillator has stopped\n");
81 rtc_write(RTC_STAT_REG_ADDR
,
82 rtc_read(RTC_STAT_REG_ADDR
) &~ (RTC_STAT_BIT_BAT
|RTC_STAT_BIT_RTCF
));
86 tmp
->tm_sec
= bcd2bin (sec
& 0x7F);
87 tmp
->tm_min
= bcd2bin (min
& 0x7F);
88 tmp
->tm_hour
= bcd2bin (hour
& 0x3F);
89 tmp
->tm_mday
= bcd2bin (mday
& 0x3F);
90 tmp
->tm_mon
= bcd2bin (mon
& 0x1F);
91 tmp
->tm_year
= bcd2bin (year
)+2000;
92 tmp
->tm_wday
= bcd2bin (wday
& 0x07);
96 DEBUGR ("Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
97 tmp
->tm_year
, tmp
->tm_mon
, tmp
->tm_mday
, tmp
->tm_wday
,
98 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
106 int rtc_set (struct rtc_time
*tmp
)
108 DEBUGR ("Set DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
109 tmp
->tm_year
, tmp
->tm_mon
, tmp
->tm_mday
, tmp
->tm_wday
,
110 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
113 rtc_write(RTC_STAT_REG_ADDR
,
114 rtc_read(RTC_STAT_REG_ADDR
) | RTC_STAT_BIT_WRTC
);
116 rtc_write (RTC_YR_REG_ADDR
, bin2bcd (tmp
->tm_year
% 100));
117 rtc_write (RTC_MON_REG_ADDR
, bin2bcd (tmp
->tm_mon
));
118 rtc_write (RTC_DAY_REG_ADDR
, bin2bcd (tmp
->tm_wday
));
119 rtc_write (RTC_DATE_REG_ADDR
, bin2bcd (tmp
->tm_mday
));
120 rtc_write (RTC_HR_REG_ADDR
, bin2bcd (tmp
->tm_hour
) | 0x80 ); /* 24h clock */
121 rtc_write (RTC_MIN_REG_ADDR
, bin2bcd (tmp
->tm_min
));
122 rtc_write (RTC_SEC_REG_ADDR
, bin2bcd (tmp
->tm_sec
));
125 rtc_write(RTC_STAT_REG_ADDR
,
126 rtc_read(RTC_STAT_REG_ADDR
) & ~RTC_STAT_BIT_WRTC
);
131 void rtc_reset (void)
139 static uchar
rtc_read (uchar reg
)
141 return (i2c_reg_read (CONFIG_SYS_I2C_RTC_ADDR
, reg
));
144 static void rtc_write (uchar reg
, uchar val
)
146 i2c_reg_write (CONFIG_SYS_I2C_RTC_ADDR
, reg
, val
);