Author: ian
Date: Wed Jan 10 02:31:59 2018
New Revision: 327757
URL: https://svnweb.freebsd.org/changeset/base/327757

Log:
  Bugfix: don't lose the am/pm mode flag when setting the time.  Unlike most
  RTC chips that have a control register bit for am/pm mode, the DS13xx series
  uses one of the high bits in the hour register.  Thus, when setting the time
  in am/pm mode, the am/pm mode flag has to be ORed into the hour.

Modified:
  head/sys/dev/iicbus/ds13rtc.c

Modified: head/sys/dev/iicbus/ds13rtc.c
==============================================================================
--- head/sys/dev/iicbus/ds13rtc.c       Wed Jan 10 02:28:10 2018        
(r327756)
+++ head/sys/dev/iicbus/ds13rtc.c       Wed Jan 10 02:31:59 2018        
(r327757)
@@ -415,7 +415,7 @@ ds13rtc_settime(device_t dev, struct timespec *ts)
        struct time_regs tregs;
        struct ds13rtc_softc *sc;
        int err;
-       uint8_t cflag, statreg, pmflag;
+       uint8_t cflag, statreg, pmflags;
 
        sc = device_get_softc(dev);
 
@@ -432,11 +432,12 @@ ds13rtc_settime(device_t dev, struct timespec *ts)
        clock_ts_to_ct(ts, &ct);
 
        /* If the chip is in AMPM mode deal with the PM flag. */
-       pmflag = 0;
+       pmflags = 0;
        if (sc->flags & SC_F_AMPM) {
+               pmflags = DS13xx_B_HOUR_AMPM;
                if (ct.hour >= 12) {
                        ct.hour -= 12;
-                       pmflag = DS13xx_B_HOUR_PM;
+                       pmflags |= DS13xx_B_HOUR_PM;
                }
                if (ct.hour == 0)
                        ct.hour = 12;
@@ -451,7 +452,7 @@ ds13rtc_settime(device_t dev, struct timespec *ts)
 
        tregs.sec   = TOBCD(ct.sec);
        tregs.min   = TOBCD(ct.min);
-       tregs.hour  = TOBCD(ct.hour) | pmflag;
+       tregs.hour  = TOBCD(ct.hour) | pmflags;
        tregs.day   = TOBCD(ct.day);
        tregs.month = TOBCD(ct.mon) | cflag;
        tregs.year  = TOBCD(ct.year % 100);
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to