Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F147912971
D12961.id34806.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D12961.id34806.diff
View Options
Index: sys/dev/iicbus/ds1307.c
===================================================================
--- sys/dev/iicbus/ds1307.c
+++ sys/dev/iicbus/ds1307.c
@@ -272,6 +272,7 @@
struct sysctl_oid *tree_node;
struct sysctl_oid_list *tree;
uint8_t secs;
+ uint8_t osc_en;
dev = (device_t)xdev;
sc = device_get_softc(dev);
@@ -286,9 +287,17 @@
device_printf(sc->sc_dev, "cannot read from RTC.\n");
return;
}
- if ((secs & DS1307_SECS_CH) != 0) {
+ if (sc->sc_mcp7941x)
+ osc_en = 0x80;
+ else
+ osc_en = 0x00;
+
+ if (((secs & DS1307_SECS_CH) ^ osc_en) != 0) {
device_printf(sc->sc_dev,
"WARNING: RTC clock stopped, check the battery.\n");
+ /* Try to turn on the oscillator */
+ secs &= ~DS1307_SECS_CH;
+ ds1307_write1(sc->sc_dev, DS1307_SECS, secs | osc_en);
}
/* Configuration parameters. */
@@ -318,7 +327,7 @@
int error;
struct clocktime ct;
struct ds1307_softc *sc;
- uint8_t data[7], hourmask;
+ uint8_t data[7], hourmask, st_mask;
sc = device_get_softc(dev);
error = iicdev_readfrom(sc->sc_dev, DS1307_SECS, data, sizeof(data),
@@ -329,7 +338,12 @@
}
/* If the clock halted, we don't have good data. */
- if (data[DS1307_SECS] & DS1307_SECS_CH)
+ if (sc->sc_mcp7941x)
+ st_mask = 0x80;
+ else
+ st_mask = 0x00;
+
+ if (((data[DS1307_SECS] & DS1307_SECS_CH) ^ st_mask) != 0)
return (EINVAL);
/* If chip is in AM/PM mode remember that. */
@@ -394,6 +408,13 @@
data[DS1307_WEEKDAY] = ct.dow;
data[DS1307_MONTH] = TOBCD(ct.mon);
data[DS1307_YEAR] = TOBCD(ct.year % 100);
+ if (sc->sc_mcp7941x) {
+ data[DS1307_SECS] |= MCP7941X_SECS_ST;
+ data[DS1307_WEEKDAY] |= MCP7941X_WEEKDAY_VBATEN;
+ if ((ct.year % 4 == 0 && ct.year % 100 != 0) ||
+ ct.year % 400 == 0)
+ data[DS1307_MONTH] |= MCP7941X_MONTH_LPYR;
+ }
/* Write the time back to RTC. */
error = iicdev_writeto(sc->sc_dev, DS1307_SECS, data, sizeof(data),
IIC_INTRWAIT);
Index: sys/dev/iicbus/ds1307reg.h
===================================================================
--- sys/dev/iicbus/ds1307reg.h
+++ sys/dev/iicbus/ds1307reg.h
@@ -36,6 +36,7 @@
#define DS1307_SECS 0x00
#define DS1307_SECS_MASK 0x7f
#define DS1307_SECS_CH 0x80
+#define MCP7941X_SECS_ST 0x80
#define DS1307_MINS 0x01
#define DS1307_MINS_MASK 0x7f
#define DS1307_HOUR 0x02
@@ -44,10 +45,12 @@
#define DS1307_HOUR_IS_PM 0x20
#define DS1307_HOUR_USE_AMPM 0x40
#define DS1307_WEEKDAY 0x03
+#define MCP7941X_WEEKDAY_VBATEN 0x08
#define DS1307_WEEKDAY_MASK 0x07
#define DS1307_DATE 0x04
#define DS1307_DATE_MASK 0x3f
#define DS1307_MONTH 0x05
+#define MCP7941X_MONTH_LPYR 0x20
#define DS1307_MONTH_MASK 0x1f
#define DS1307_YEAR 0x06
#define DS1307_YEAR_MASK 0xff
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Mar 15, 3:10 PM (5 h, 8 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
29720880
Default Alt Text
D12961.id34806.diff (2 KB)
Attached To
Mode
D12961: DS1307: Add the mcp7941x enable bit
Attached
Detach File
Event Timeline
Log In to Comment