#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/spi/spi.h>
#define M41T93_REG_SSEC 0
#define M41T93_REG_ST_SEC 1
#define M41T93_REG_CENT_HOUR 3
#define M41T93_REG_WDAY 4
#define M41T93_REG_YEAR 7
#define M41T93_REG_ALM_HOUR_HT 0xc
#define M41T93_REG_FLAGS 0xf
#define M41T93_FLAG_ST (1 << 7)
#define M41T93_FLAG_OF (1 << 2)
#define M41T93_FLAG_BL (1 << 4)
#define M41T93_FLAG_HT (1 << 6)
static inline int m41t93_set_reg(struct spi_device *spi, u8 addr, u8 data)
return spi_write(spi, buf, sizeof(buf));
static int m41t93_set_time(struct device *dev, struct rtc_time *tm)
struct spi_device *spi = to_spi_device(dev);
u8 * const data = &buf[1];
dev_dbg(dev, "%s secs=%d, mins=%d, "
"hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n",
"write", tm->tm_sec, tm->tm_min,
tm->tm_hour, tm->tm_mday,
tm->tm_mon, tm->tm_year, tm->tm_wday);
dev_warn(&spi->dev, "unsupported date (before 2000-01-01).\n");