Lines Matching +full:no +full:- +full:read +full:- +full:rollover
1 /*-
2 * Copyright (c) 2014-2015 Luiz Otavio O Souza <loos@FreeBSD.org>
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
29 * Driver for Maxim DS3231[N] real-time clock/calendar.
87 error = ds3231_read1(sc->sc_dev, DS3231_CONTROL, &sc->sc_ctrl);
89 device_printf(sc->sc_dev, "cannot read from RTC.\n");
102 data = sc->sc_ctrl & ~DS3231_CTRL_MASK;
103 error = ds3231_write1(sc->sc_dev, DS3231_CONTROL, data);
105 device_printf(sc->sc_dev, "cannot write to RTC.\n");
115 error = ds3231_read1(sc->sc_dev, DS3231_STATUS, &sc->sc_status);
117 device_printf(sc->sc_dev, "cannot read from RTC.\n");
130 data = sc->sc_status;
135 error = ds3231_write1(sc->sc_dev, DS3231_STATUS, data);
137 device_printf(sc->sc_dev, "cannot write to RTC.\n");
149 error = iicdev_readfrom(sc->sc_dev, DS3231_TEMP, buf8, sizeof(buf8),
168 *temp = -(*temp);
198 newc = conv = (sc->sc_ctrl & DS3231_CTRL_CONV) ? 1 : 0;
200 if (error != 0 || req->newptr == NULL)
206 if (sc->sc_status & DS3231_STATUS_BUSY)
208 sc->sc_ctrl |= DS3231_CTRL_CONV;
227 bbsqw = newb = (sc->sc_ctrl & DS3231_CTRL_BBSQW) ? 1 : 0;
229 if (error != 0 || req->newptr == NULL)
232 sc->sc_ctrl &= ~DS3231_CTRL_BBSQW;
234 sc->sc_ctrl |= DS3231_CTRL_BBSQW;
254 tmp = (sc->sc_ctrl & DS3231_CTRL_RS_MASK) >> DS3231_CTRL_RS_SHIFT;
256 tmp = nitems(ds3231_sqw_freq) - 1;
259 if (error != 0 || req->newptr == NULL)
266 sc->sc_ctrl &= ~DS3231_CTRL_RS_MASK;
267 sc->sc_ctrl |= newf << DS3231_CTRL_RS_SHIFT;
281 rtrn = -1;
286 } else if ((len > 2 && strncasecmp("square-wave", buf, len) == 0) ||
305 if (sc->sc_ctrl & DS3231_CTRL_INTCN) {
310 strlcpy(buf, "square-wave", sizeof(buf));
313 if (error != 0 || req->newptr == NULL)
316 if (newm != -1 && mode != newm) {
317 sc->sc_ctrl &= ~DS3231_CTRL_INTCN;
319 sc->sc_ctrl |= DS3231_CTRL_INTCN;
338 tmp = en32khz = (sc->sc_status & DS3231_STATUS_EN32KHZ) ? 1 : 0;
340 if (error != 0 || req->newptr == NULL)
343 sc->sc_status &= ~DS3231_STATUS_EN32KHZ;
345 sc->sc_status |= DS3231_STATUS_EN32KHZ;
379 sc->sc_dev = dev;
380 sc->sc_addr = iicbus_get_addr(dev);
381 sc->sc_last_c = -1;
382 sc->sc_year0 = 0;
383 sc->enum_hook.ich_func = ds3231_start;
384 sc->enum_hook.ich_arg = dev;
387 * We have to wait until interrupts are enabled. Usually I2C read
390 if (config_intrhook_establish(&sc->enum_hook) != 0)
419 config_intrhook_disestablish(&sc->enum_hook);
428 if (sc->sc_status & DS3231_STATUS_OSF) {
429 device_printf(sc->sc_dev,
436 * writes fail, because a factory-fresh chip is in a special mode that
457 "DS3231 battery-backed square-wave output enable");
461 "DS3231 square-wave output frequency");
471 * clock_settime() method to be called just after top-of-second;
472 * resetting the time resets top-of-second in the hardware.
490 device_printf(dev, "cannot read from RTC.\n");
493 if (sc->sc_status & DS3231_STATUS_OSF)
496 error = iicdev_readfrom(sc->sc_dev, DS3231_SECS, data, sizeof(data),
499 device_printf(dev, "cannot read from RTC.\n");
505 sc->sc_use_ampm = true;
521 * a century rollover. If this is the first time we're seeing it,
525 if (sc->sc_last_c == -1)
526 sc->sc_last_c = c;
527 else if (c != sc->sc_last_c) {
528 sc->sc_year0 += 0x100;
529 sc->sc_last_c = c;
531 bct.year |= sc->sc_year0;
533 clock_dbgprint_bcd(sc->sc_dev, CLOCK_DBG_READ, &bct);
534 return (clock_bcd_to_ts(&bct, ts, sc->sc_use_ampm));
549 * We request a timespec with no resolution-adjustment. That also
552 ts->tv_sec -= utc_offset();
553 clock_ts_to_bcd(ts, &bct, sc->sc_use_ampm);
554 clock_dbgprint_bcd(sc->sc_dev, CLOCK_DBG_WRITE, &bct);
557 if (sc->sc_use_ampm) {
571 if (sc->sc_last_c)
583 * Unlike most hardware, the osc-was-stopped bit does not clear itself
586 if (sc->sc_status & DS3231_STATUS_OSF) {
588 device_printf(dev, "cannot read from RTC.\n");
591 sc->sc_status &= ~DS3231_STATUS_OSF;