37#include "opt_platform.h"
43#include <sys/kernel.h>
45#include <sys/module.h>
48#include <dev/ofw/ofw_bus.h>
49#include <dev/ofw/ofw_bus_subr.h>
58#define RTC8583_SC_REG 0x01
59#define RTC8583_USERSRAM_REG 0x10
60#define MAX_TRANSFER 16
72 struct intr_config_hook
92 void *buffer, uint16_t buflen,
int waithow);
98 uint16_t buflen,
int waithow)
104 slaveaddr = iicbus_get_addr(slavedev);
107 memcpy(newbuf + 1, buffer, buflen);
136 config_intrhook_disestablish(&sc->
init_hook);
141 clock_register_flags(sc->
dev, 1000000, CLOCKF_SETTIME_NO_ADJ);
142 clock_schedule(sc->
dev, 1);
151 if (!ofw_bus_status_okay(
dev))
155 device_set_desc(
dev,
"EPSON RTC-8583");
156 return (BUS_PROBE_DEFAULT);
167 sc = device_get_softc(
dev);
177 if (config_intrhook_establish(&sc->
init_hook) != 0)
187 clock_unregister(
dev);
195 struct bcd_clocktime bct;
197 uint8_t y, ytmp, sreg;
200 sc = device_get_softc(
dev);
232 if (!validbcd(tregs.
msec))
236 bct.nsec = bcd2bin(tregs.
msec) * 10 * 1000 * 1000;
239 bct.hour = tregs.
hour & 0x3f;
240 bct.day = tregs.
day & 0x3f;
241 bct.mon = tregs.
month & 0x1f;
242 bct.year = bin2bcd(sreg % 100);
244 clock_dbgprint_bcd(sc->
dev, CLOCK_DBG_READ, &bct);
245 return (clock_bcd_to_ts(&bct, ts,
false));
252 struct bcd_clocktime bct;
257 sc = device_get_softc(
dev);
258 ts->tv_sec -= utc_offset();
259 clock_ts_to_bcd(ts, &bct,
false);
260 clock_dbgprint_bcd(sc->
dev, CLOCK_DBG_WRITE, &bct);
263 tregs.
msec = bin2bcd(ts->tv_nsec / (10 * 1000 * 1000));
266 tregs.
hour = bct.hour;
267 tregs.
day = bct.day | (bct.year & 0x03 << 6);
268 tregs.
month = bct.mon;
274 sreg = bcd2bin(bct.year & 0xff);
static ds13_compat_data compat_data[]
int iicbus_request_bus(device_t bus, device_t dev, int how)
int iicbus_release_bus(device_t bus, device_t dev)
int iicdev_readfrom(device_t slavedev, uint8_t regaddr, void *buffer, uint16_t buflen, int waithow)
int iicbus_transfer_excl(device_t dev, struct iic_msg *msgs, uint32_t nmsgs, int how)
MODULE_DEPEND(rtc8583, iicbus, IICBUS_MINVER, IICBUS_PREFVER, IICBUS_MAXVER)
static devclass_t rtc8583_devclass
static int rtc8583_attach(device_t dev)
static device_method_t rtc8583_methods[]
static int rtc8583_write1(struct rtc8583_softc *sc, uint8_t reg, uint8_t val)
static int rtc8583_writeto(device_t slavedev, uint8_t regaddr, void *buffer, uint16_t buflen, int waithow)
static void rtc8583_init(void *arg)
DRIVER_MODULE(rtc8583, iicbus, rtc8583_driver, rtc8583_devclass, NULL, NULL)
#define RTC8583_USERSRAM_REG
static driver_t rtc8583_driver
IICBUS_FDT_PNP_INFO(compat_data)
MODULE_VERSION(rtc8583, 1)
static int rtc8583_read1(struct rtc8583_softc *sc, uint8_t reg, uint8_t *data)
static int rtc8583_detach(device_t dev)
static int rtc8583_settime(device_t dev, struct timespec *ts)
static int rtc8583_gettime(device_t dev, struct timespec *ts)
static int rtc8583_probe(device_t dev)
struct intr_config_hook init_hook