HomeFreeBSD

MFC r306288, r314936, r325527, r327971, r328005, r328039, r328068-r328069,

Description

MFC r306288, r314936, r325527, r327971, r328005, r328039, r328068-r328069,

r328301-r328303

r306288:
Fix ds1307 probing

'compat' can never be NULL, because the compatible check loop ends when
compat->ocd_str is NULL. This causes ds1307 to attach to any unclaimed i2c
device.

r314936:
Validate values read from the RTC before trying BCD decoding

Submitted by: cem
Reported by: Michael Gmelin <freebsd@grem.de>
Tested by: Oleksandr Tymoshenko <gonzo@bluezbox.com>
Sponsored by: Dell EMC

r325527:
DS1307: Add the mcp7941x enable bit

Summary:
Existing code recognizes the mcp7941x RTC, but this RTC has an
enable bit at the same location as the "Clock Halt" bit on the ds1307, with an
opposite assertion (set == on, whereas CH set == clock stopped). Thus the
current code halts the clock, with no way to enable it.

Reviewed By: ian
Differential Revision: https://reviews.freebsd.org/D12961

r327971:
Add RTC clock conversions for BCD values, with non-panic validation.

RTC clock hardware frequently uses BCD numbers. Currently the low-level
bcd2bin() and bin2bcd() functions will KASSERT if given out-of-range BCD
values. Every RTC driver must implement its own code for validating the
unreliable data coming from the hardware to avoid a potential kernel panic.

This change introduces two new functions, clock_bcd_to_ts() and
clock_ts_to_bcd(). The former validates its inputs and returns EINVAL if any
values are out of range. The latter guarantees the returned data will be
valid BCD in a known format (4-digit years, etc).

A new bcd_clocktime structure is used with the new functions. It is similar
to the original clocktime structure, but defines the fields holding BCD
values as uint8_t (uint16_t for year), and adds a PM flag for handling hours
using AM/PM mode.

PR: 224813
Differential Revision: https://reviews.freebsd.org/D13730 (no reviewers)

r328005:
Convert the x86 RTC driver to use new validated BCD<->timespec conversions.

New common routines were added to kern/subr_clock.c for converting between
calendrical time expressed in BCD and struct timespec. The new functions
return EINVAL on error, as expected when the clock hardware does not provide
valid time.

PR: 224813
Differential Revision: https://reviews.freebsd.org/D13731 (no reviewers)

r328039:
Add static inline rtcin_locked() and rtcout_locked() functions for doing a
related series of operations without doing a lock/unlock for each byte.
Use them when reading and writing the entire set of time registers.

The original rtcin() and writertc() functions which do lock/unlock on each
byte still exist, because they are public and called by outside code.

r328068:
Move some code around and rename a couple variables; no functional changes.

The static atrtc_set() function was called only from clock_settime(), so
just move its contents entirely into clock_settime() and delete atrtc_set().

Rename the struct bcd_clocktime variables from 'ct' to 'bct'. I had
originally wanted to emphasize how identical the clocktime and bcd_clocktime
structs were, but things evolved to the point where the structs are not at
all identical anymore, so now emphasizing the difference seems better.

r328069:
Remove redundant critical_enter/exit() calls. The block of code delimited
by these calls is now protected by a spin mutex (obscured within the
RTC_LOCK/RTC_UNLOCK macros).

Reported by: bde@

r328301:
Switch to using the bcd_clocktime conversion functinos that validate the BCD
data without panicking, and have common code for handling AM/PM mode.

r328302:
Switch to using the bcd_clocktime conversion functions that validate the BCD
data without panicking, and have common code for handling AM/PM mode.

r328303:
Switch to using the bcd_clocktime conversion functions that validate the BCD
data without panicking, and have common code for handling AM/PM mode.

Details

Provenance
ianAuthored on
Reviewer
ian
Differential Revision
D12961: DS1307: Add the mcp7941x enable bit
Parents
rS331495: MFC r327756-r327758
Branches
Unknown
Tags
Unknown