Lines Matching +full:battery +full:- +full:backed

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
30 * Driver for Dallas/Maxim DS13xx real-time clock/calendar chips:
32 * - DS1307 = Original/basic rtc + 56 bytes ram; 5v only.
33 * - DS1308 = Updated 1307, available in 1.8v-5v variations.
34 * - DS1337 = Like 1308, integrated xtal, 32khz output on at powerup.
35 * - DS1338 = Like 1308, integrated xtal.
36 * - DS1339 = Like 1337, integrated xtal, integrated trickle charger.
37 * - DS1340 = Like 1338, ST M41T00 compatible.
38 * - DS1341 = Like 1338, can slave-sync osc to external clock signal.
39 * - DS1342 = Like 1341 but requires different xtal.
40 * - DS1371 = 32-bit binary counter, watchdog timer.
41 * - DS1372 = 32-bit binary counter, 64-bit unique id in rom.
42 * - DS1374 = 32-bit binary counter, watchdog timer, trickle charger.
43 * - DS1375 = Like 1308 but only 16 bytes ram.
44 * - DS1388 = Rtc, watchdog timer, 512 bytes eeprom (not sram).
169 bool is_binary_counter; /* Chip has 32-bit binary counter. */
173 * We use the compat_data table to look up hint strings in the non-FDT case, so
207 return (iicdev_readfrom(sc->dev, reg, val, sizeof(*val), IIC_WAIT)); in read_reg()
214 return (iicdev_writeto(sc->dev, reg, &val, sizeof(val), IIC_WAIT)); in write_reg()
222 if ((err = iicdev_readfrom(sc->dev, sc->secaddr, tregs, in read_timeregs()
233 return (iicdev_writeto(sc->dev, sc->secaddr, tregs, in write_timeregs()
243 if ((err = iicdev_readfrom(sc->dev, sc->secaddr, buf, sizeof(buf), in read_timeword()
256 return (iicdev_writeto(sc->dev, sc->secaddr, buf, sizeof(buf), in write_timeword()
273 * the oscillator, disables signals/outputs in battery-backed mode in ds13rtc_start()
276 switch (sc->chiptype) { in ds13rtc_start()
301 device_printf(sc->dev, "missing init code for this chiptype\n"); in ds13rtc_start()
312 if (read_reg(sc, sc->osfaddr, &statreg) != 0) { in ds13rtc_start()
313 device_printf(sc->dev, "cannot read RTC clock status bit\n"); in ds13rtc_start()
317 device_printf(sc->dev, in ds13rtc_start()
318 "WARNING: RTC battery failed; time is invalid\n"); in ds13rtc_start()
326 if ((sc->chiptype != TYPE_DS1340) && !sc->is_binary_counter) { in ds13rtc_start()
327 if (read_reg(sc, sc->secaddr + 2, &statreg) != 0) { in ds13rtc_start()
328 device_printf(sc->dev, in ds13rtc_start()
333 sc->use_ampm = true; in ds13rtc_start()
338 * Schedule RTC updates to happen just after top-of-second. in ds13rtc_start()
340 clock_register_flags(sc->dev, 1000000, CLOCKF_SETTIME_NO_ADJ); in ds13rtc_start()
341 clock_schedule(sc->dev, 1); in ds13rtc_start()
356 if ((err = read_reg(sc, sc->osfaddr, &statreg)) != 0) { in ds13rtc_gettime()
363 if (sc->is_binary_counter) { in ds13rtc_gettime()
364 ts->tv_nsec = 0; in ds13rtc_gettime()
365 return (read_timeword(sc, &ts->tv_sec)); in ds13rtc_gettime()
376 if (sc->use_ampm) in ds13rtc_gettime()
392 * clock_ct_to_ts() infer the century from the 2-digit year. in ds13rtc_gettime()
394 if (sc->use_century) in ds13rtc_gettime()
397 clock_dbgprint_bcd(sc->dev, CLOCK_DBG_READ, &bct); in ds13rtc_gettime()
398 err = clock_bcd_to_ts(&bct, ts, sc->use_ampm); in ds13rtc_gettime()
415 * We request a timespec with no resolution-adjustment. That also in ds13rtc_settime()
418 ts->tv_sec -= utc_offset(); in ds13rtc_settime()
421 if (sc->is_binary_counter) in ds13rtc_settime()
422 return (write_timeword(sc, ts->tv_sec)); in ds13rtc_settime()
424 clock_ts_to_bcd(ts, &bct, sc->use_ampm); in ds13rtc_settime()
425 clock_dbgprint_bcd(sc->dev, CLOCK_DBG_WRITE, &bct); in ds13rtc_settime()
429 if (sc->use_ampm) { in ds13rtc_settime()
437 if (sc->use_century) { in ds13rtc_settime()
456 if (sc->osfaddr != sc->secaddr) { in ds13rtc_settime()
457 if ((err = read_reg(sc, sc->osfaddr, &statreg)) != 0) in ds13rtc_settime()
461 err = write_reg(sc, sc->osfaddr, statreg); in ds13rtc_settime()
478 return (ofw_bus_search_compatible(dev, compat_data)->ocd_data); in ds13rtc_get_chiptype()
494 for (cdata = compat_data; cdata->ocd_str != NULL; ++cdata) { in ds13rtc_get_chiptype()
495 if (strcmp(htype, cdata->ocd_str) == 0) in ds13rtc_get_chiptype()
498 return (cdata->ocd_data); in ds13rtc_get_chiptype()
529 sc->dev = dev; in ds13rtc_attach()
530 sc->busdev = device_get_parent(dev); in ds13rtc_attach()
535 if ((sc->chiptype = ds13rtc_get_chiptype(dev)) == TYPE_NONE) { in ds13rtc_attach()
541 if (sc->chiptype == TYPE_DS1388) in ds13rtc_attach()
542 sc->secaddr = DS1388_R_SECOND; in ds13rtc_attach()
544 sc->secaddr = DS13xx_R_SECOND; in ds13rtc_attach()
547 * The OSF/CH (osc failed/clock-halted) bit appears in different in ds13rtc_attach()
549 * because it has no internal oscillator; we just point to an always- in ds13rtc_attach()
552 switch (sc->chiptype) { in ds13rtc_attach()
556 sc->osfaddr = DS13xx_R_SECOND; in ds13rtc_attach()
563 sc->osfaddr = DS133x_R_STATUS; in ds13rtc_attach()
564 sc->use_century = true; in ds13rtc_attach()
567 sc->osfaddr = DS1340_R_STATUS; in ds13rtc_attach()
572 sc->osfaddr = DS137x_R_STATUS; in ds13rtc_attach()
573 sc->is_binary_counter = true; in ds13rtc_attach()
576 sc->osfaddr = DS1388_R_STATUS; in ds13rtc_attach()