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