6 #include <linux/kernel.h>
7 #include <linux/module.h>
11 #include <linux/rtc.h>
13 #include <linux/slab.h>
29 static u8 bq4802_read_io(
struct bq4802 *
p,
int off)
34 static void bq4802_write_io(
struct bq4802 *
p,
int off,
u8 val)
39 static u8 bq4802_read_mem(
struct bq4802 *
p,
int off)
44 static void bq4802_write_mem(
struct bq4802 *
p,
int off,
u8 val)
52 struct bq4802 *
p = platform_get_drvdata(pdev);
59 val = p->
read(p, 0x0e);
69 century = p->
read(p, 0x0f);
71 p->
write(p, 0x0e, val);
73 spin_unlock_irqrestore(&p->
lock, flags);
92 static int bq4802_set_time(
struct device *dev,
struct rtc_time *tm)
95 struct bq4802 *p = platform_get_drvdata(pdev);
101 century = year / 100;
120 val = p->
read(p, 0x0e);
121 p->
write(p, 0x0e, val | 0x08);
123 p->
write(p, 0x00, sec);
124 p->
write(p, 0x02, min);
125 p->
write(p, 0x04, hrs);
126 p->
write(p, 0x06, day);
127 p->
write(p, 0x09, mon);
128 p->
write(p, 0x0a, yrs);
129 p->
write(p, 0x0f, century);
131 p->
write(p, 0x0e, val);
133 spin_unlock_irqrestore(&p->
lock, flags);
139 .read_time = bq4802_read_time,
140 .set_time = bq4802_set_time,
162 p->
read = bq4802_read_io;
163 p->
write = bq4802_write_io;
166 p->
read = bq4802_read_mem;
167 p->
write = bq4802_write_mem;
173 platform_set_drvdata(pdev, p);
177 if (IS_ERR(p->
rtc)) {
178 err = PTR_ERR(p->
rtc);
196 struct bq4802 *p = platform_get_drvdata(pdev);
202 platform_set_drvdata(pdev,
NULL);
214 .name =
"rtc-bq4802",
217 .probe = bq4802_probe,