From owner-svn-src-head@freebsd.org Wed Jan 10 02:57:04 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 76594E608EB; Wed, 10 Jan 2018 02:57:04 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4D8387E236; Wed, 10 Jan 2018 02:57:04 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 8B6221FD0B; Wed, 10 Jan 2018 02:57:03 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w0A2v3S1050274; Wed, 10 Jan 2018 02:57:03 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w0A2v3Sj050273; Wed, 10 Jan 2018 02:57:03 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201801100257.w0A2v3Sj050273@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Wed, 10 Jan 2018 02:57:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r327758 - head/sys/dev/iicbus X-SVN-Group: head X-SVN-Commit-Author: ian X-SVN-Commit-Paths: head/sys/dev/iicbus X-SVN-Commit-Revision: 327758 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Jan 2018 02:57:04 -0000 Author: ian Date: Wed Jan 10 02:57:03 2018 New Revision: 327758 URL: https://svnweb.freebsd.org/changeset/base/327758 Log: Convert a collection of unrelated bitwise flags to a collection of boolean vars in the softc. It makes the code more compact and readable, and actually uses less memory too. Modified: head/sys/dev/iicbus/ds13rtc.c Modified: head/sys/dev/iicbus/ds13rtc.c ============================================================================== --- head/sys/dev/iicbus/ds13rtc.c Wed Jan 10 02:31:59 2018 (r327757) +++ head/sys/dev/iicbus/ds13rtc.c Wed Jan 10 02:57:03 2018 (r327758) @@ -162,16 +162,14 @@ struct time_regs { struct ds13rtc_softc { device_t dev; device_t busdev; - u_int flags; /* SC_F_* flags */ u_int chiptype; /* Type of DS13xx chip */ uint8_t secaddr; /* Address of seconds register */ uint8_t osfaddr; /* Address of register with OSF */ + bool use_ampm; /* Use AM/PM mode. */ + bool use_century; /* Use the Century bit. */ + bool is_binary_counter; /* Chip has 32-bit binary counter. */ }; -#define SC_F_BINARY (1u << 0) /* Time is 32-bit binary counter */ -#define SC_F_AMPM (1u << 1) /* Use PM flag in hours reg */ -#define SC_F_CENTURY (1u << 2) /* Use century bit */ - /* * We use the compat_data table to look up hint strings in the non-FDT case, so * define the struct locally when we don't get it from ofw_bus_subr.h. @@ -326,14 +324,14 @@ ds13rtc_start(void *arg) * chips that do AM/PM mode, the flag bit is in the hours register, * which is secaddr+2. */ - if ((sc->chiptype != TYPE_DS1340) && !(sc->flags & SC_F_BINARY)) { + if ((sc->chiptype != TYPE_DS1340) && !sc->is_binary_counter) { if (read_reg(sc, sc->secaddr + 2, &statreg) != 0) { device_printf(sc->dev, "cannot read RTC clock AM/PM bit\n"); return; } if (statreg & DS13xx_B_HOUR_AMPM) - sc->flags |= SC_F_AMPM; + sc->use_ampm = true; } /* @@ -363,7 +361,7 @@ ds13rtc_gettime(device_t dev, struct timespec *ts) return (EINVAL); /* hardware is good, time is not. */ /* If the chip counts time in binary, we just read and return it. */ - if (sc->flags & SC_F_BINARY) { + if (sc->is_binary_counter) { ts->tv_nsec = 0; return (read_timeword(sc, &ts->tv_sec)); } @@ -376,7 +374,7 @@ ds13rtc_gettime(device_t dev, struct timespec *ts) return (err); } - if (sc->flags & SC_F_AMPM) + if (sc->use_ampm) hourmask = DS13xx_M_12HOUR; else hourmask = DS13xx_M_24HOUR; @@ -389,7 +387,7 @@ ds13rtc_gettime(device_t dev, struct timespec *ts) ct.year = FROMBCD(tregs.year & DS13xx_M_YEAR); ct.nsec = 0; - if (sc->flags & SC_F_AMPM) { + if (sc->use_ampm) { if (ct.hour == 12) ct.hour = 0; if (tregs.hour & DS13xx_B_HOUR_PM) @@ -400,7 +398,7 @@ ds13rtc_gettime(device_t dev, struct timespec *ts) * If this chip has a century bit, honor it. Otherwise let * clock_ct_to_ts() infer the century from the 2-digit year. */ - if (sc->flags & SC_F_CENTURY) + if (sc->use_century) ct.year += (tregs.month & DS13xx_B_MONTH_CENTURY) ? 2000 : 1900; err = clock_ct_to_ts(&ct, ts); @@ -426,14 +424,14 @@ ds13rtc_settime(device_t dev, struct timespec *ts) ts->tv_sec -= utc_offset(); /* If the chip counts time in binary, store tv_sec and we're done. */ - if (sc->flags & SC_F_BINARY) + if (sc->is_binary_counter) return (write_timeword(sc, ts->tv_sec)); clock_ts_to_ct(ts, &ct); /* If the chip is in AMPM mode deal with the PM flag. */ pmflags = 0; - if (sc->flags & SC_F_AMPM) { + if (sc->use_ampm) { pmflags = DS13xx_B_HOUR_AMPM; if (ct.hour >= 12) { ct.hour -= 12; @@ -445,7 +443,7 @@ ds13rtc_settime(device_t dev, struct timespec *ts) /* If the chip has a century bit, set it as needed. */ cflag = 0; - if (sc->flags & SC_F_CENTURY) { + if (sc->use_century) { if (ct.year >= 2000) cflag |= DS13xx_B_MONTH_CENTURY; } @@ -572,7 +570,7 @@ ds13rtc_attach(device_t dev) case TYPE_DS1342: case TYPE_DS1375: sc->osfaddr = DS133x_R_STATUS; - sc->flags |= SC_F_CENTURY; + sc->use_century = true; break; case TYPE_DS1340: sc->osfaddr = DS1340_R_STATUS; @@ -581,7 +579,7 @@ ds13rtc_attach(device_t dev) case TYPE_DS1372: case TYPE_DS1374: sc->osfaddr = DS137x_R_STATUS; - sc->flags |= SC_F_BINARY; + sc->is_binary_counter = true; break; case TYPE_DS1388: sc->osfaddr = DS1388_R_STATUS;