ds13rtc.c (331496) | ds13rtc.c (331503) |
---|---|
1/*- 2 * Copyright (c) 2017 Ian Lepore <ian@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) 2017 Ian Lepore <ian@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/ds13rtc.c 331496 2018-03-24 20:40:16Z ian $"); | 28__FBSDID("$FreeBSD: stable/11/sys/dev/iicbus/ds13rtc.c 331503 2018-03-24 23:01:10Z ian $"); |
29 30/* 31 * Driver for Dallas/Maxim DS13xx real-time clock/calendar chips: 32 * 33 * - DS1307 = Original/basic rtc + 56 bytes ram; 5v only. 34 * - DS1308 = Updated 1307, available in 1.8v-5v variations. 35 * - DS1337 = Like 1308, integrated xtal, 32khz output on at powerup. 36 * - DS1338 = Like 1308, integrated xtal. --- 353 unchanged lines hidden (view full) --- 390 391 /* 392 * If this chip has a century bit, honor it. Otherwise let 393 * clock_ct_to_ts() infer the century from the 2-digit year. 394 */ 395 if (sc->use_century) 396 bct.year += (tregs.month & DS13xx_B_MONTH_CENTURY) ? 0x100 : 0; 397 | 29 30/* 31 * Driver for Dallas/Maxim DS13xx real-time clock/calendar chips: 32 * 33 * - DS1307 = Original/basic rtc + 56 bytes ram; 5v only. 34 * - DS1308 = Updated 1307, available in 1.8v-5v variations. 35 * - DS1337 = Like 1308, integrated xtal, 32khz output on at powerup. 36 * - DS1338 = Like 1308, integrated xtal. --- 353 unchanged lines hidden (view full) --- 390 391 /* 392 * If this chip has a century bit, honor it. Otherwise let 393 * clock_ct_to_ts() infer the century from the 2-digit year. 394 */ 395 if (sc->use_century) 396 bct.year += (tregs.month & DS13xx_B_MONTH_CENTURY) ? 0x100 : 0; 397 |
398 clock_dbgprint_bcd(sc->dev, CLOCK_DBG_READ, &bct); |
|
398 err = clock_bcd_to_ts(&bct, ts, sc->use_ampm); 399 400 return (err); 401} 402 403static int 404ds13rtc_settime(device_t dev, struct timespec *ts) 405{ --- 11 unchanged lines hidden (view full) --- 417 */ 418 ts->tv_sec -= utc_offset(); 419 420 /* If the chip counts time in binary, store tv_sec and we're done. */ 421 if (sc->is_binary_counter) 422 return (write_timeword(sc, ts->tv_sec)); 423 424 clock_ts_to_bcd(ts, &bct, sc->use_ampm); | 399 err = clock_bcd_to_ts(&bct, ts, sc->use_ampm); 400 401 return (err); 402} 403 404static int 405ds13rtc_settime(device_t dev, struct timespec *ts) 406{ --- 11 unchanged lines hidden (view full) --- 418 */ 419 ts->tv_sec -= utc_offset(); 420 421 /* If the chip counts time in binary, store tv_sec and we're done. */ 422 if (sc->is_binary_counter) 423 return (write_timeword(sc, ts->tv_sec)); 424 425 clock_ts_to_bcd(ts, &bct, sc->use_ampm); |
426 clock_dbgprint_bcd(sc->dev, CLOCK_DBG_WRITE, &bct); |
|
425 426 /* If the chip is in AMPM mode deal with the PM flag. */ 427 pmflags = 0; 428 if (sc->use_ampm) { 429 pmflags = DS13xx_B_HOUR_AMPM; 430 if (bct.ispm) 431 pmflags |= DS13xx_B_HOUR_PM; 432 } --- 185 unchanged lines hidden --- | 427 428 /* If the chip is in AMPM mode deal with the PM flag. */ 429 pmflags = 0; 430 if (sc->use_ampm) { 431 pmflags = DS13xx_B_HOUR_AMPM; 432 if (bct.ispm) 433 pmflags |= DS13xx_B_HOUR_PM; 434 } --- 185 unchanged lines hidden --- |