37 #include <linux/device.h>
38 #include <linux/errno.h>
40 #include <linux/kernel.h>
41 #include <linux/string.h>
42 #include <linux/slab.h>
43 #include <linux/rtc.h>
45 #include <linux/module.h>
48 #define DRV_VERSION "0.6"
50 #define PCF2123_REG_CTRL1 (0x00)
51 #define PCF2123_REG_CTRL2 (0x01)
52 #define PCF2123_REG_SC (0x02)
53 #define PCF2123_REG_MN (0x03)
54 #define PCF2123_REG_HR (0x04)
55 #define PCF2123_REG_DM (0x05)
56 #define PCF2123_REG_DW (0x06)
57 #define PCF2123_REG_MO (0x07)
58 #define PCF2123_REG_YR (0x08)
60 #define PCF2123_SUBADDR (1 << 4)
61 #define PCF2123_WRITE ((0 << 7) | PCF2123_SUBADDR)
62 #define PCF2123_READ ((1 << 7) | PCF2123_SUBADDR)
81 static inline void pcf2123_delay_trec(
void)
91 u8 txbuf[1], rxbuf[1];
104 pcf2123_delay_trec();
105 return sprintf(buffer,
"0x%x\n", rxbuf[0]);
109 const char *buffer,
size_t count) {
126 ret = spi_write(spi, txbuf,
sizeof(txbuf));
129 pcf2123_delay_trec();
136 u8 txbuf[1], rxbuf[7];
141 rxbuf,
sizeof(rxbuf));
144 pcf2123_delay_trec();
156 dev_dbg(dev,
"%s: tm is secs=%d, mins=%d, hours=%d, "
157 "mday=%d, mon=%d, year=%d, wday=%d\n",
166 dev_err(dev,
"retrieved date/time is not valid.\n");
171 static int pcf2123_rtc_set_time(
struct device *dev,
struct rtc_time *tm)
177 dev_dbg(dev,
"%s: tm is secs=%d, mins=%d, hours=%d, "
178 "mday=%d, mon=%d, year=%d, wday=%d\n",
186 ret = spi_write(spi, txbuf, 2);
189 pcf2123_delay_trec();
201 ret = spi_write(spi, txbuf,
sizeof(txbuf));
204 pcf2123_delay_trec();
209 ret = spi_write(spi, txbuf, 2);
212 pcf2123_delay_trec();
218 .read_time = pcf2123_rtc_read_time,
219 .set_time = pcf2123_rtc_set_time,
226 u8 txbuf[2], rxbuf[2];
237 dev_dbg(&spi->
dev,
"resetting RTC (0x%02X 0x%02X)\n",
239 ret = spi_write(spi, txbuf, 2 *
sizeof(
u8));
242 pcf2123_delay_trec();
247 dev_dbg(&spi->
dev,
"stopping RTC (0x%02X 0x%02X)\n",
249 ret = spi_write(spi, txbuf, 2 *
sizeof(
u8));
252 pcf2123_delay_trec();
256 dev_dbg(&spi->
dev,
"checking for presence of RTC (0x%02X)\n",
259 rxbuf, 2 *
sizeof(
u8));
260 dev_dbg(&spi->
dev,
"received data from RTC (0x%02X 0x%02X)\n",
264 pcf2123_delay_trec();
266 if (!(rxbuf[0] & 0x20)) {
278 ret = spi_write(spi, txbuf,
sizeof(txbuf));
281 pcf2123_delay_trec();
295 for (i = 0; i < 16; i++) {
299 pdata->
regs[
i].attr.attr.name = pdata->
regs[
i].name;
300 pdata->
regs[
i].attr.show = pcf2123_show;
301 pdata->
regs[
i].attr.store = pcf2123_store;
304 dev_err(&spi->
dev,
"Unable to create sysfs %s\n",
305 pdata->
regs[i].name);
313 for (i--; i >= 0; i--)
332 for (i = 0; i < 16; i++)
333 if (pdata->
regs[i].name[0])
335 &pdata->
regs[i].attr);
344 .name =
"rtc-pcf2123",
347 .probe = pcf2123_probe,