Deleted Added
full compact
ds3231.c (323467) ds3231.c (327653)
1/*-
2 * Copyright (c) 2014-2015 Luiz Otavio O Souza <loos@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2014-2015 Luiz Otavio O Souza <loos@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: stable/11/sys/dev/iicbus/ds3231.c 323467 2017-09-11 22:21:15Z ian $");
28__FBSDID("$FreeBSD: stable/11/sys/dev/iicbus/ds3231.c 327653 2018-01-06 23:04:14Z ian $");
29
30/*
31 * Driver for Maxim DS3231[N] real-time clock/calendar.
32 */
33
34#include "opt_platform.h"
35
36#include <sys/param.h>

--- 385 unchanged lines hidden (view full) ---

422 /*
423 * Warn if the clock stopped, but don't restart it until the first
424 * clock_settime() call.
425 */
426 if (sc->sc_status & DS3231_STATUS_OSF) {
427 device_printf(sc->sc_dev,
428 "WARNING: RTC clock stopped, check the battery.\n");
429 }
29
30/*
31 * Driver for Maxim DS3231[N] real-time clock/calendar.
32 */
33
34#include "opt_platform.h"
35
36#include <sys/param.h>

--- 385 unchanged lines hidden (view full) ---

422 /*
423 * Warn if the clock stopped, but don't restart it until the first
424 * clock_settime() call.
425 */
426 if (sc->sc_status & DS3231_STATUS_OSF) {
427 device_printf(sc->sc_dev,
428 "WARNING: RTC clock stopped, check the battery.\n");
429 }
430 /* Ack any pending alarm interrupt. */
431 if (ds3231_status_write(sc, 1, 1) != 0)
432 return;
433 /* Always enable the oscillator. */
434 if (ds3231_ctrl_write(sc) != 0)
435 return;
436
430
431 /*
432 * Ack any pending alarm interrupts and clear the EOSC bit to ensure the
433 * clock runs even when on battery power. Do not give up if these
434 * writes fail, because a factory-fresh chip is in a special mode that
435 * disables much of the chip to save battery power, and the only thing
436 * that gets it out of that mode is writing to the time registers. In
437 * these pristine chips, the EOSC and alarm bits are zero already, so
438 * the first valid write of time will get everything running properly.
439 */
440 ds3231_status_write(sc, 1, 1);
441 ds3231_ctrl_write(sc);
442
437 /* Temperature. */
438 SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "temperature",
439 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0,
440 ds3231_temp_sysctl, "IK", "Current temperature");
441 /* Configuration parameters. */
442 SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "temp_conv",
443 CTLFLAG_RW | CTLTYPE_UINT | CTLFLAG_MPSAFE, sc, 0,
444 ds3231_conv_sysctl, "IU",

--- 118 unchanged lines hidden (view full) ---

563 ct.hour = 12;
564 } else
565 pmflags = 0;
566
567 data[DS3231_SECS] = TOBCD(ct.sec);
568 data[DS3231_MINS] = TOBCD(ct.min);
569 data[DS3231_HOUR] = TOBCD(ct.hour) | pmflags;
570 data[DS3231_DATE] = TOBCD(ct.day);
443 /* Temperature. */
444 SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "temperature",
445 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE, sc, 0,
446 ds3231_temp_sysctl, "IK", "Current temperature");
447 /* Configuration parameters. */
448 SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, "temp_conv",
449 CTLFLAG_RW | CTLTYPE_UINT | CTLFLAG_MPSAFE, sc, 0,
450 ds3231_conv_sysctl, "IU",

--- 118 unchanged lines hidden (view full) ---

569 ct.hour = 12;
570 } else
571 pmflags = 0;
572
573 data[DS3231_SECS] = TOBCD(ct.sec);
574 data[DS3231_MINS] = TOBCD(ct.min);
575 data[DS3231_HOUR] = TOBCD(ct.hour) | pmflags;
576 data[DS3231_DATE] = TOBCD(ct.day);
571 data[DS3231_WEEKDAY] = ct.dow;
577 data[DS3231_WEEKDAY] = ct.dow + 1;
572 data[DS3231_MONTH] = TOBCD(ct.mon);
573 data[DS3231_YEAR] = TOBCD(ct.year % 100);
574 if (sc->sc_last_c)
575 data[DS3231_MONTH] |= DS3231_C_MASK;
576
577 /* Write the time back to RTC. */
578 error = iicdev_writeto(dev, DS3231_SECS, data, sizeof(data),
579 IIC_INTRWAIT);

--- 46 unchanged lines hidden ---
578 data[DS3231_MONTH] = TOBCD(ct.mon);
579 data[DS3231_YEAR] = TOBCD(ct.year % 100);
580 if (sc->sc_last_c)
581 data[DS3231_MONTH] |= DS3231_C_MASK;
582
583 /* Write the time back to RTC. */
584 error = iicdev_writeto(dev, DS3231_SECS, data, sizeof(data),
585 IIC_INTRWAIT);

--- 46 unchanged lines hidden ---