ds1307.c (331496) | ds1307.c (331503) |
---|---|
1/*- 2 * Copyright (c) 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) 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/ds1307.c 331496 2018-03-24 20:40:16Z ian $"); | 28__FBSDID("$FreeBSD: stable/11/sys/dev/iicbus/ds1307.c 331503 2018-03-24 23:01:10Z ian $"); |
29 30/* 31 * Driver for Maxim DS1307 I2C real-time clock/calendar. 32 */ 33 34#include "opt_platform.h" 35 36#include <sys/param.h> --- 317 unchanged lines hidden (view full) --- 354 bct.ispm = (data[DS1307_HOUR] & DS1307_HOUR_IS_PM) != 0; 355 bct.sec = data[DS1307_SECS] & DS1307_SECS_MASK; 356 bct.min = data[DS1307_MINS] & DS1307_MINS_MASK; 357 bct.hour = data[DS1307_HOUR] & hourmask; 358 bct.day = data[DS1307_DATE] & DS1307_DATE_MASK; 359 bct.mon = data[DS1307_MONTH] & DS1307_MONTH_MASK; 360 bct.year = data[DS1307_YEAR] & DS1307_YEAR_MASK; 361 | 29 30/* 31 * Driver for Maxim DS1307 I2C real-time clock/calendar. 32 */ 33 34#include "opt_platform.h" 35 36#include <sys/param.h> --- 317 unchanged lines hidden (view full) --- 354 bct.ispm = (data[DS1307_HOUR] & DS1307_HOUR_IS_PM) != 0; 355 bct.sec = data[DS1307_SECS] & DS1307_SECS_MASK; 356 bct.min = data[DS1307_MINS] & DS1307_MINS_MASK; 357 bct.hour = data[DS1307_HOUR] & hourmask; 358 bct.day = data[DS1307_DATE] & DS1307_DATE_MASK; 359 bct.mon = data[DS1307_MONTH] & DS1307_MONTH_MASK; 360 bct.year = data[DS1307_YEAR] & DS1307_YEAR_MASK; 361 |
362 clock_dbgprint_bcd(sc->sc_dev, CLOCK_DBG_READ, &bct); |
|
362 return (clock_bcd_to_ts(&bct, ts, sc->sc_use_ampm)); 363} 364 365static int 366ds1307_settime(device_t dev, struct timespec *ts) 367{ 368 struct bcd_clocktime bct; 369 struct ds1307_softc *sc; --- 4 unchanged lines hidden (view full) --- 374 sc = device_get_softc(dev); 375 376 /* 377 * We request a timespec with no resolution-adjustment. That also 378 * disables utc adjustment, so apply that ourselves. 379 */ 380 ts->tv_sec -= utc_offset(); 381 clock_ts_to_bcd(ts, &bct, sc->sc_use_ampm); | 363 return (clock_bcd_to_ts(&bct, ts, sc->sc_use_ampm)); 364} 365 366static int 367ds1307_settime(device_t dev, struct timespec *ts) 368{ 369 struct bcd_clocktime bct; 370 struct ds1307_softc *sc; --- 4 unchanged lines hidden (view full) --- 375 sc = device_get_softc(dev); 376 377 /* 378 * We request a timespec with no resolution-adjustment. That also 379 * disables utc adjustment, so apply that ourselves. 380 */ 381 ts->tv_sec -= utc_offset(); 382 clock_ts_to_bcd(ts, &bct, sc->sc_use_ampm); |
383 clock_dbgprint_bcd(sc->sc_dev, CLOCK_DBG_WRITE, &bct); |
|
382 383 /* If the chip is in AM/PM mode, adjust hour and set flags as needed. */ 384 if (sc->sc_use_ampm) { 385 pmflags = DS1307_HOUR_USE_AMPM; 386 if (bct.ispm) 387 pmflags |= DS1307_HOUR_IS_PM; 388 } else 389 pmflags = 0; --- 46 unchanged lines hidden --- | 384 385 /* If the chip is in AM/PM mode, adjust hour and set flags as needed. */ 386 if (sc->sc_use_ampm) { 387 pmflags = DS1307_HOUR_USE_AMPM; 388 if (bct.ispm) 389 pmflags |= DS1307_HOUR_IS_PM; 390 } else 391 pmflags = 0; --- 46 unchanged lines hidden --- |