Lines Matching +full:start +full:- +full:year
1 // SPDX-License-Identifier: GPL-2.0-only
2 /* rtc-bq4802.c: TI BQ4802 RTC driver.
32 return inb(p->ioport + off); in bq4802_read_io()
37 outb(val, p->ioport + off); in bq4802_write_io()
42 return readb(p->regs + off); in bq4802_read_mem()
47 writeb(val, p->regs + off); in bq4802_write_mem()
57 spin_lock_irqsave(&p->lock, flags); in bq4802_read_time()
59 val = p->read(p, 0x0e); in bq4802_read_time()
60 p->write(p, 0xe, val | 0x08); in bq4802_read_time()
62 tm->tm_sec = p->read(p, 0x00); in bq4802_read_time()
63 tm->tm_min = p->read(p, 0x02); in bq4802_read_time()
64 tm->tm_hour = p->read(p, 0x04); in bq4802_read_time()
65 tm->tm_mday = p->read(p, 0x06); in bq4802_read_time()
66 tm->tm_mon = p->read(p, 0x09); in bq4802_read_time()
67 tm->tm_year = p->read(p, 0x0a); in bq4802_read_time()
68 tm->tm_wday = p->read(p, 0x08); in bq4802_read_time()
69 century = p->read(p, 0x0f); in bq4802_read_time()
71 p->write(p, 0x0e, val); in bq4802_read_time()
73 spin_unlock_irqrestore(&p->lock, flags); in bq4802_read_time()
75 tm->tm_sec = bcd2bin(tm->tm_sec); in bq4802_read_time()
76 tm->tm_min = bcd2bin(tm->tm_min); in bq4802_read_time()
77 tm->tm_hour = bcd2bin(tm->tm_hour); in bq4802_read_time()
78 tm->tm_mday = bcd2bin(tm->tm_mday); in bq4802_read_time()
79 tm->tm_mon = bcd2bin(tm->tm_mon); in bq4802_read_time()
80 tm->tm_year = bcd2bin(tm->tm_year); in bq4802_read_time()
81 tm->tm_wday = bcd2bin(tm->tm_wday); in bq4802_read_time()
84 tm->tm_year += (century * 100); in bq4802_read_time()
85 tm->tm_year -= 1900; in bq4802_read_time()
87 tm->tm_mon--; in bq4802_read_time()
97 unsigned int year; in bq4802_set_time() local
99 year = tm->tm_year + 1900; in bq4802_set_time()
100 century = year / 100; in bq4802_set_time()
101 yrs = year % 100; in bq4802_set_time()
103 mon = tm->tm_mon + 1; /* tm_mon starts at zero */ in bq4802_set_time()
104 day = tm->tm_mday; in bq4802_set_time()
105 hrs = tm->tm_hour; in bq4802_set_time()
106 min = tm->tm_min; in bq4802_set_time()
107 sec = tm->tm_sec; in bq4802_set_time()
117 spin_lock_irqsave(&p->lock, flags); in bq4802_set_time()
119 val = p->read(p, 0x0e); in bq4802_set_time()
120 p->write(p, 0x0e, val | 0x08); in bq4802_set_time()
122 p->write(p, 0x00, sec); in bq4802_set_time()
123 p->write(p, 0x02, min); in bq4802_set_time()
124 p->write(p, 0x04, hrs); in bq4802_set_time()
125 p->write(p, 0x06, day); in bq4802_set_time()
126 p->write(p, 0x09, mon); in bq4802_set_time()
127 p->write(p, 0x0a, yrs); in bq4802_set_time()
128 p->write(p, 0x0f, century); in bq4802_set_time()
130 p->write(p, 0x0e, val); in bq4802_set_time()
132 spin_unlock_irqrestore(&p->lock, flags); in bq4802_set_time()
144 struct bq4802 *p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL); in bq4802_probe()
145 int err = -ENOMEM; in bq4802_probe()
150 spin_lock_init(&p->lock); in bq4802_probe()
152 p->r = platform_get_resource(pdev, IORESOURCE_MEM, 0); in bq4802_probe()
153 if (!p->r) { in bq4802_probe()
154 p->r = platform_get_resource(pdev, IORESOURCE_IO, 0); in bq4802_probe()
155 err = -EINVAL; in bq4802_probe()
156 if (!p->r) in bq4802_probe()
159 if (p->r->flags & IORESOURCE_IO) { in bq4802_probe()
160 p->ioport = p->r->start; in bq4802_probe()
161 p->read = bq4802_read_io; in bq4802_probe()
162 p->write = bq4802_write_io; in bq4802_probe()
163 } else if (p->r->flags & IORESOURCE_MEM) { in bq4802_probe()
164 p->regs = devm_ioremap(&pdev->dev, p->r->start, in bq4802_probe()
165 resource_size(p->r)); in bq4802_probe()
166 if (!p->regs){ in bq4802_probe()
167 err = -ENOMEM; in bq4802_probe()
170 p->read = bq4802_read_mem; in bq4802_probe()
171 p->write = bq4802_write_mem; in bq4802_probe()
173 err = -EINVAL; in bq4802_probe()
179 p->rtc = devm_rtc_device_register(&pdev->dev, "bq4802", in bq4802_probe()
181 if (IS_ERR(p->rtc)) { in bq4802_probe()
182 err = PTR_ERR(p->rtc); in bq4802_probe()
193 MODULE_ALIAS("platform:rtc-bq4802");
197 .name = "rtc-bq4802",