11 #include <linux/module.h>
13 #include <linux/rtc.h>
14 #include <linux/types.h>
19 #include <linux/slab.h>
23 #define DS2404_STATUS_REG 0x200
24 #define DS2404_CONTROL_REG 0x201
25 #define DS2404_RTC_REG 0x202
27 #define DS2404_WRITE_SCRATCHPAD_CMD 0x0f
28 #define DS2404_READ_SCRATCHPAD_CMD 0xaa
29 #define DS2404_COPY_SCRATCHPAD_CMD 0x55
30 #define DS2404_READ_MEMORY_CMD 0xf0
70 for (i = 0; i <
ARRAY_SIZE(ds2404_gpio); i++) {
74 ds2404_gpio[i].
name, err);
81 chip->
gpio = ds2404_gpio;
90 static void ds2404_gpio_unmap(
struct ds2404 *chip)
99 .map_io = ds2404_gpio_map,
100 .unmap_io = ds2404_gpio_unmap,
103 static void ds2404_reset(
struct device *
dev)
118 for (i = 0; i < 8; i++) {
128 static u8 ds2404_read_byte(
struct device *dev)
135 for (i = 0; i < 8; i++) {
151 ds2404_write_byte(dev, offset & 0xff);
152 ds2404_write_byte(dev, (offset >> 8) & 0xff);
154 *out++ = ds2404_read_byte(dev);
157 static void ds2404_write_memory(
struct device *dev,
u16 offset,
165 ds2404_write_byte(dev, offset & 0xff);
166 ds2404_write_byte(dev, (offset >> 8) & 0xff);
168 for (i = 0; i <
length; i++)
169 ds2404_write_byte(dev, out[i]);
174 ta01 = ds2404_read_byte(dev);
175 ta02 = ds2404_read_byte(dev);
176 es = ds2404_read_byte(dev);
178 for (i = 0; i <
length; i++) {
179 if (out[i] != ds2404_read_byte(dev)) {
187 ds2404_write_byte(dev, ta01);
188 ds2404_write_byte(dev, ta02);
189 ds2404_write_byte(dev, es);
196 static void ds2404_enable_osc(
struct device *dev)
199 ds2404_write_memory(dev, 0x201, 1, in);
202 static int ds2404_read_time(
struct device *dev,
struct rtc_time *dt)
204 unsigned long time = 0;
206 ds2404_read_memory(dev, 0x203, 4, (
u8 *)&time);
213 static int ds2404_set_mmss(
struct device *dev,
unsigned long secs)
216 ds2404_write_memory(dev, 0x203, 4, (
u8 *)&time);
221 .read_time = ds2404_read_time,
222 .set_mmss = ds2404_set_mmss,
235 chip->
ops = &ds2404_gpio_ops;
237 retval = chip->
ops->map_io(chip, pdev, pdata);
241 dev_info(&pdev->
dev,
"using GPIOs RST:%d, CLK:%d, DQ:%d\n",
245 platform_set_drvdata(pdev, chip);
249 if (IS_ERR(chip->
rtc)) {
250 retval = PTR_ERR(chip->
rtc);
254 ds2404_enable_osc(&pdev->
dev);
258 chip->
ops->unmap_io(chip);
266 struct ds2404 *chip = platform_get_drvdata(dev);
272 chip->
ops->unmap_io(chip);
280 .remove = rtc_remove,
287 static __init int ds2404_init(
void)
292 static __exit void ds2404_exit(
void)