35#include "opt_platform.h"
41#include <sys/kernel.h>
43#include <sys/module.h>
46#include <dev/ofw/ofw_bus.h>
47#include <dev/ofw/ofw_bus_subr.h>
57#define HYM8563_CTRL1 0x00
58#define HYM8563_CTRL1_TEST (1 << 7)
59#define HYM8563_CTRL1_STOP (1 << 5)
60#define HYM8563_CTRL1_TESTC (1 << 3)
62#define HYM8563_CTRL2 0x01
63#define HYM8563_CTRL2_TI_TP (1 << 4)
64#define HYM8563_CTRL2_AF (1 << 3)
65#define HYM8563_CTRL2_TF (1 << 2)
66#define HYM8563_CTRL2_AIE (1 << 1)
67#define HYM8563_CTRL2_TIE (1 << 0)
69#define HYM8563_SEC 0x02
70#define HYM8563_SEC_VL (1 << 7)
72#define HYM8563_MIN 0x03
73#define HYM8563_HOUR 0x04
74#define HYM8563_DAY 0x05
75#define HYM8563_WEEKDAY 0x06
76#define HYM8563_MONTH 0x07
77#define HYM8563_MONTH_CENTURY (1 << 7)
78#define HYM8563_YEAR 0x08
127 struct bcd_clocktime bct;
131 sc = device_get_softc(
dev);
136 device_printf(sc->
dev,
"Cannot read time registers: %d\n", rv);
143 device_printf(sc->
dev,
144 "WARNING: RTC battery failed; time is invalid\n");
148 bzero(&bct,
sizeof(bct));
149 bct.sec =
buf[0] & 0x7F;
150 bct.min =
buf[1] & 0x7F;
151 bct.hour =
buf[2] & 0x3f;
152 bct.day =
buf[3] & 0x3f;
154 bct.mon =
buf[5] & 0x1f;
155 bct.year =
buf[6] & 0xff;
159 clock_dbgprint_bcd(sc->
dev, CLOCK_DBG_READ, &bct);
160 return (clock_bcd_to_ts(&bct, ts,
false));
167 struct bcd_clocktime bct;
171 sc = device_get_softc(
dev);
172 ts->tv_sec -= utc_offset();
173 clock_ts_to_bcd(ts, &bct,
false);
174 clock_dbgprint_bcd(sc->
dev, CLOCK_DBG_WRITE, &bct);
182 buf[6] = bct.year & 0xFF;
189 device_printf(sc->
dev,
"Cannot write CTRL1 register: %d\n", rv);
196 device_printf(sc->
dev,
"Cannot write time registers: %d\n", rv);
204 device_printf(sc->
dev,
"Cannot write CTRL1 register: %d\n", rv);
219 config_intrhook_disestablish(&sc->
init_hook);
224 device_printf(sc->
dev,
"Cannot init CTRL1 register: %d\n", rv);
231 device_printf(sc->
dev,
"Cannot read CTRL2 register: %d\n", rv);
234 rv &= ~HYM8563_CTRL2_TI_TP;
235 rv &= ~HYM8563_CTRL2_AF;
236 rv &= ~HYM8563_CTRL2_TF;
239 device_printf(sc->
dev,
"Cannot write CTRL2 register: %d\n", rv);
246 clock_register_flags(sc->
dev, 1000000, 0);
247 clock_schedule(sc->
dev, 1);
256 if (!ofw_bus_status_okay(
dev))
260 device_set_desc(
dev,
"HYM8694 RTC");
261 return (BUS_PROBE_DEFAULT);
272 sc = device_get_softc(
dev);
281 if (config_intrhook_establish(&sc->
init_hook) != 0)
291 clock_unregister(
dev);
static ds13_compat_data compat_data[]
MODULE_VERSION(hym8563, 1)
static int hym8563_read_1(struct hym8563_softc *sc, uint8_t reg, uint8_t *data)
static int hym8563_write_1(struct hym8563_softc *sc, uint8_t reg, uint8_t val)
MODULE_DEPEND(hym8563, iicbus, IICBUS_MINVER, IICBUS_PREFVER, IICBUS_MAXVER)
static int hym8563_probe(device_t dev)
static DEFINE_CLASS_0(hym8563_rtc, hym8563_driver, hym8563_methods, sizeof(struct hym8563_softc))
static device_method_t hym8563_methods[]
static int hym8563_write_buf(struct hym8563_softc *sc, uint8_t reg, uint8_t *buf, uint16_t buflen)
static int hym8563_read_buf(struct hym8563_softc *sc, uint8_t reg, uint8_t *buf, uint16_t buflen)
static int hym8563_detach(device_t dev)
IICBUS_FDT_PNP_INFO(compat_data)
DRIVER_MODULE(hym8563, iicbus, hym8563_driver, hym8563_devclass, NULL, NULL)
static int hym8563_attach(device_t dev)
static int hym8563_gettime(device_t dev, struct timespec *ts)
static devclass_t hym8563_devclass
static void hym8563_init(void *arg)
#define HYM8563_CTRL1_STOP
#define HYM8563_MONTH_CENTURY
static int hym8563_settime(device_t dev, struct timespec *ts)
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)
struct intr_config_hook init_hook