52#include "opt_platform.h"
58#include <sys/endian.h>
59#include <sys/kernel.h>
60#include <sys/libkern.h>
61#include <sys/module.h>
66#include <dev/ofw/openfirm.h>
67#include <dev/ofw/ofw_bus.h>
68#include <dev/ofw/ofw_bus_subr.h>
77#define DS13xx_ADDR 0xd0
83#define DS13xx_R_NONE 0xff
85#define DS130x_R_CONTROL 0x07
86#define DS133x_R_CONTROL 0x0e
87#define DS1340_R_CONTROL 0x07
88#define DS1341_R_CONTROL 0x0e
89#define DS1371_R_CONTROL 0x07
90#define DS1372_R_CONTROL 0x07
91#define DS1374_R_CONTROL 0x07
92#define DS1375_R_CONTROL 0x0e
93#define DS1388_R_CONTROL 0x0c
95#define DS13xx_R_SECOND 0x00
96#define DS1388_R_SECOND 0x01
98#define DS130x_R_STATUS DS13xx_R_NONE
99#define DS133x_R_STATUS 0x0f
100#define DS1340_R_STATUS 0x09
101#define DS137x_R_STATUS 0x08
102#define DS1388_R_STATUS 0x0b
104#define DS13xx_B_STATUS_OSF 0x80
105#define DS13xx_B_HOUR_AMPM 0x40
106#define DS13xx_B_HOUR_PM 0x20
107#define DS13xx_B_MONTH_CENTURY 0x80
109#define DS13xx_M_SECOND 0x7f
110#define DS13xx_M_MINUTE 0x7f
111#define DS13xx_M_12HOUR 0x1f
112#define DS13xx_M_24HOUR 0x3f
113#define DS13xx_M_DAY 0x3f
114#define DS13xx_M_MONTH 0x1f
115#define DS13xx_M_YEAR 0xff
140 "Dallas/Maxim DS1307 RTC",
141 "Dallas/Maxim DS1308 RTC",
142 "Dallas/Maxim DS1337 RTC",
143 "Dallas/Maxim DS1338 RTC",
144 "Dallas/Maxim DS1339 RTC",
145 "Dallas/Maxim DS1340 RTC",
146 "Dallas/Maxim DS1341 RTC",
147 "Dallas/Maxim DS1342 RTC",
148 "Dallas/Maxim DS1371 RTC",
149 "Dallas/Maxim DS1372 RTC",
150 "Dallas/Maxim DS1374 RTC",
151 "Dallas/Maxim DS1375 RTC",
152 "Dallas/Maxim DS1388 RTC",
247 *secs = le32dec(
buf);
257 le32enc(
buf, (uint32_t)secs);
266 uint8_t ctlreg, statreg;
303 device_printf(sc->
dev,
"missing init code for this chiptype\n");
315 device_printf(sc->
dev,
"cannot read RTC clock status bit\n");
319 device_printf(sc->
dev,
320 "WARNING: RTC battery failed; time is invalid\n");
330 device_printf(sc->
dev,
331 "cannot read RTC clock AM/PM bit\n");
342 clock_register_flags(sc->
dev, 1000000, CLOCKF_SETTIME_NO_ADJ);
343 clock_schedule(sc->
dev, 1);
349 struct bcd_clocktime bct;
353 uint8_t statreg, hourmask;
355 sc = device_get_softc(
dev);
374 device_printf(
dev,
"cannot read RTC time\n");
387 bct.hour = tregs.
hour & hourmask;
399 clock_dbgprint_bcd(sc->
dev, CLOCK_DBG_READ, &bct);
400 err = clock_bcd_to_ts(&bct, ts, sc->
use_ampm);
408 struct bcd_clocktime bct;
412 uint8_t cflag, statreg, pmflags;
414 sc = device_get_softc(
dev);
420 ts->tv_sec -= utc_offset();
426 clock_ts_to_bcd(ts, &bct, sc->
use_ampm);
427 clock_dbgprint_bcd(sc->
dev, CLOCK_DBG_WRITE, &bct);
440 if (bct.year >= 2000)
446 tregs.
hour = bct.hour | pmflags;
448 tregs.
month = bct.mon | cflag;
449 tregs.
year = bct.year & 0xff;
450 tregs.
wday = bct.dow;
462 statreg &= ~DS13xx_B_STATUS_OSF;
470 device_printf(
dev,
"cannot update RTC time\n");
488 if (resource_string_value(device_get_name(
dev),
489 device_get_unit(
dev),
"compatible", &htype) != 0)
497 if (strcmp(htype, cdata->
ocd_str) == 0)
510 if (!ofw_bus_status_okay(
dev))
512 goodrv = BUS_PROBE_GENERIC;
514 goodrv = BUS_PROBE_NOWILDCARD;
530 sc = device_get_softc(
dev);
538 device_printf(
dev,
"impossible: cannot determine chip type\n");
595 clock_unregister(
dev);
#define DS13xx_B_STATUS_OSF
static void ds13rtc_start(void *arg)
static int read_timeregs(struct ds13rtc_softc *sc, struct time_regs *tregs)
static devclass_t ds13rtc_devclass
static int write_timeword(struct ds13rtc_softc *sc, time_t secs)
static driver_t ds13rtc_driver
static int ds13rtc_attach(device_t dev)
MODULE_VERSION(ds13rtc, 1)
static int read_reg(struct ds13rtc_softc *sc, uint8_t reg, uint8_t *val)
static int ds13rtc_probe(device_t dev)
static int ds13rtc_settime(device_t dev, struct timespec *ts)
static int ds13rtc_gettime(device_t dev, struct timespec *ts)
#define DS13xx_B_MONTH_CENTURY
static device_method_t ds13rtc_methods[]
DRIVER_MODULE(ds13rtc, iicbus, ds13rtc_driver, ds13rtc_devclass, NULL, NULL)
static int write_timeregs(struct ds13rtc_softc *sc, struct time_regs *tregs)
static ds13_compat_data compat_data[]
MODULE_DEPEND(ds13rtc, iicbus, IICBB_MINVER, IICBB_PREFVER, IICBB_MAXVER)
static const char * desc_strings[]
static int ds13rtc_detach(device_t dev)
static int ds13rtc_get_chiptype(device_t dev)
#define DS13xx_B_HOUR_AMPM
IICBUS_FDT_PNP_INFO(compat_data)
static int write_reg(struct ds13rtc_softc *sc, uint8_t reg, uint8_t val)
static int read_timeword(struct ds13rtc_softc *sc, time_t *secs)
CTASSERT(nitems(desc_strings)==TYPE_COUNT)
int iicdev_readfrom(device_t slavedev, uint8_t regaddr, void *buffer, uint16_t buflen, int waithow)
int iicdev_writeto(device_t slavedev, uint8_t regaddr, void *buffer, uint16_t buflen, int waithow)