blob: d090565707390daf27f6411336c51606298e6692 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Akshay Bhated13d892015-12-03 14:41:21 -05002/*
3 * Driver for the Epson RTC module RX-8010 SJ
4 *
5 * Copyright(C) Timesys Corporation 2015
6 * Copyright(C) General Electric Company 2015
Akshay Bhated13d892015-12-03 14:41:21 -05007 */
8
9#include <linux/bcd.h>
10#include <linux/bitops.h>
11#include <linux/i2c.h>
12#include <linux/kernel.h>
13#include <linux/module.h>
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +020014#include <linux/regmap.h>
Akshay Bhated13d892015-12-03 14:41:21 -050015#include <linux/rtc.h>
16
Bartosz Golaszewskie9e4c2d2020-09-14 17:45:52 +020017#define RX8010_SEC 0x10
18#define RX8010_MIN 0x11
19#define RX8010_HOUR 0x12
20#define RX8010_WDAY 0x13
21#define RX8010_MDAY 0x14
22#define RX8010_MONTH 0x15
23#define RX8010_YEAR 0x16
24#define RX8010_RESV17 0x17
25#define RX8010_ALMIN 0x18
26#define RX8010_ALHOUR 0x19
27#define RX8010_ALWDAY 0x1A
28#define RX8010_TCOUNT0 0x1B
29#define RX8010_TCOUNT1 0x1C
30#define RX8010_EXT 0x1D
31#define RX8010_FLAG 0x1E
32#define RX8010_CTRL 0x1F
Akshay Bhated13d892015-12-03 14:41:21 -050033/* 0x20 to 0x2F are user registers */
Bartosz Golaszewskie9e4c2d2020-09-14 17:45:52 +020034#define RX8010_RESV30 0x30
35#define RX8010_RESV31 0x31
36#define RX8010_IRQ 0x32
Akshay Bhated13d892015-12-03 14:41:21 -050037
Bartosz Golaszewskie9e4c2d2020-09-14 17:45:52 +020038#define RX8010_EXT_WADA BIT(3)
Akshay Bhated13d892015-12-03 14:41:21 -050039
Bartosz Golaszewskie9e4c2d2020-09-14 17:45:52 +020040#define RX8010_FLAG_VLF BIT(1)
41#define RX8010_FLAG_AF BIT(3)
42#define RX8010_FLAG_TF BIT(4)
43#define RX8010_FLAG_UF BIT(5)
Akshay Bhated13d892015-12-03 14:41:21 -050044
Bartosz Golaszewskie9e4c2d2020-09-14 17:45:52 +020045#define RX8010_CTRL_AIE BIT(3)
46#define RX8010_CTRL_UIE BIT(5)
47#define RX8010_CTRL_STOP BIT(6)
48#define RX8010_CTRL_TEST BIT(7)
Akshay Bhated13d892015-12-03 14:41:21 -050049
Bartosz Golaszewskie9e4c2d2020-09-14 17:45:52 +020050#define RX8010_ALARM_AE BIT(7)
Akshay Bhated13d892015-12-03 14:41:21 -050051
52static const struct i2c_device_id rx8010_id[] = {
53 { "rx8010", 0 },
54 { }
55};
56MODULE_DEVICE_TABLE(i2c, rx8010_id);
57
Alexandre Belloni782d3eb2021-02-02 12:22:15 +010058static const __maybe_unused struct of_device_id rx8010_of_match[] = {
Javier Martinez Canillas81b779c2017-03-03 11:29:16 -030059 { .compatible = "epson,rx8010" },
60 { }
61};
62MODULE_DEVICE_TABLE(of, rx8010_of_match);
63
Akshay Bhated13d892015-12-03 14:41:21 -050064struct rx8010_data {
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +020065 struct regmap *regs;
Akshay Bhated13d892015-12-03 14:41:21 -050066 struct rtc_device *rtc;
67 u8 ctrlreg;
Akshay Bhated13d892015-12-03 14:41:21 -050068};
69
70static irqreturn_t rx8010_irq_1_handler(int irq, void *dev_id)
71{
72 struct i2c_client *client = dev_id;
73 struct rx8010_data *rx8010 = i2c_get_clientdata(client);
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +020074 int flagreg, err;
Akshay Bhated13d892015-12-03 14:41:21 -050075
Alexandre Belloni2dbbedb2021-01-19 23:06:50 +010076 rtc_lock(rx8010->rtc);
Akshay Bhated13d892015-12-03 14:41:21 -050077
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +020078 err = regmap_read(rx8010->regs, RX8010_FLAG, &flagreg);
79 if (err) {
Alexandre Belloni2dbbedb2021-01-19 23:06:50 +010080 rtc_unlock(rx8010->rtc);
Akshay Bhated13d892015-12-03 14:41:21 -050081 return IRQ_NONE;
82 }
83
84 if (flagreg & RX8010_FLAG_VLF)
85 dev_warn(&client->dev, "Frequency stop detected\n");
86
87 if (flagreg & RX8010_FLAG_TF) {
88 flagreg &= ~RX8010_FLAG_TF;
89 rtc_update_irq(rx8010->rtc, 1, RTC_PF | RTC_IRQF);
90 }
91
92 if (flagreg & RX8010_FLAG_AF) {
93 flagreg &= ~RX8010_FLAG_AF;
94 rtc_update_irq(rx8010->rtc, 1, RTC_AF | RTC_IRQF);
95 }
96
97 if (flagreg & RX8010_FLAG_UF) {
98 flagreg &= ~RX8010_FLAG_UF;
99 rtc_update_irq(rx8010->rtc, 1, RTC_UF | RTC_IRQF);
100 }
101
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +0200102 err = regmap_write(rx8010->regs, RX8010_FLAG, flagreg);
Alexandre Belloni2dbbedb2021-01-19 23:06:50 +0100103 rtc_unlock(rx8010->rtc);
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +0200104 return err ? IRQ_NONE : IRQ_HANDLED;
Akshay Bhated13d892015-12-03 14:41:21 -0500105}
106
107static int rx8010_get_time(struct device *dev, struct rtc_time *dt)
108{
109 struct rx8010_data *rx8010 = dev_get_drvdata(dev);
Bartosz Golaszewskif7026992020-09-14 17:45:54 +0200110 u8 date[RX8010_YEAR - RX8010_SEC + 1];
Bartosz Golaszewski75677972020-09-14 17:45:51 +0200111 int flagreg, err;
Akshay Bhated13d892015-12-03 14:41:21 -0500112
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +0200113 err = regmap_read(rx8010->regs, RX8010_FLAG, &flagreg);
114 if (err)
115 return err;
Akshay Bhated13d892015-12-03 14:41:21 -0500116
117 if (flagreg & RX8010_FLAG_VLF) {
118 dev_warn(dev, "Frequency stop detected\n");
119 return -EINVAL;
120 }
121
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +0200122 err = regmap_bulk_read(rx8010->regs, RX8010_SEC, date, sizeof(date));
123 if (err)
124 return err;
Akshay Bhated13d892015-12-03 14:41:21 -0500125
126 dt->tm_sec = bcd2bin(date[RX8010_SEC - RX8010_SEC] & 0x7f);
127 dt->tm_min = bcd2bin(date[RX8010_MIN - RX8010_SEC] & 0x7f);
128 dt->tm_hour = bcd2bin(date[RX8010_HOUR - RX8010_SEC] & 0x3f);
129 dt->tm_mday = bcd2bin(date[RX8010_MDAY - RX8010_SEC] & 0x3f);
130 dt->tm_mon = bcd2bin(date[RX8010_MONTH - RX8010_SEC] & 0x1f) - 1;
131 dt->tm_year = bcd2bin(date[RX8010_YEAR - RX8010_SEC]) + 100;
132 dt->tm_wday = ffs(date[RX8010_WDAY - RX8010_SEC] & 0x7f);
133
Alexandre Belloni22652ba2018-02-19 16:23:56 +0100134 return 0;
Akshay Bhated13d892015-12-03 14:41:21 -0500135}
136
137static int rx8010_set_time(struct device *dev, struct rtc_time *dt)
138{
139 struct rx8010_data *rx8010 = dev_get_drvdata(dev);
Bartosz Golaszewskif7026992020-09-14 17:45:54 +0200140 u8 date[RX8010_YEAR - RX8010_SEC + 1];
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +0200141 int err;
Akshay Bhated13d892015-12-03 14:41:21 -0500142
Akshay Bhated13d892015-12-03 14:41:21 -0500143 /* set STOP bit before changing clock/calendar */
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +0200144 err = regmap_set_bits(rx8010->regs, RX8010_CTRL, RX8010_CTRL_STOP);
145 if (err)
Bartosz Golaszewski13952c92020-09-14 17:45:53 +0200146 return err;
Akshay Bhated13d892015-12-03 14:41:21 -0500147
148 date[RX8010_SEC - RX8010_SEC] = bin2bcd(dt->tm_sec);
149 date[RX8010_MIN - RX8010_SEC] = bin2bcd(dt->tm_min);
150 date[RX8010_HOUR - RX8010_SEC] = bin2bcd(dt->tm_hour);
151 date[RX8010_MDAY - RX8010_SEC] = bin2bcd(dt->tm_mday);
152 date[RX8010_MONTH - RX8010_SEC] = bin2bcd(dt->tm_mon + 1);
153 date[RX8010_YEAR - RX8010_SEC] = bin2bcd(dt->tm_year - 100);
154 date[RX8010_WDAY - RX8010_SEC] = bin2bcd(1 << dt->tm_wday);
155
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +0200156 err = regmap_bulk_write(rx8010->regs, RX8010_SEC, date, sizeof(date));
157 if (err)
Bartosz Golaszewski13952c92020-09-14 17:45:53 +0200158 return err;
Akshay Bhated13d892015-12-03 14:41:21 -0500159
160 /* clear STOP bit after changing clock/calendar */
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +0200161 err = regmap_clear_bits(rx8010->regs, RX8010_CTRL, RX8010_CTRL_STOP);
162 if (err)
Bartosz Golaszewski13952c92020-09-14 17:45:53 +0200163 return err;
Akshay Bhated13d892015-12-03 14:41:21 -0500164
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +0200165 err = regmap_clear_bits(rx8010->regs, RX8010_FLAG, RX8010_FLAG_VLF);
166 if (err)
167 return err;
Akshay Bhated13d892015-12-03 14:41:21 -0500168
Akshay Bhated13d892015-12-03 14:41:21 -0500169 return 0;
170}
171
Bartosz Golaszewskiba1bcaf2020-09-17 13:46:56 +0200172static int rx8010_init(struct device *dev)
Akshay Bhated13d892015-12-03 14:41:21 -0500173{
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +0200174 struct rx8010_data *rx8010 = dev_get_drvdata(dev);
Akshay Bhated13d892015-12-03 14:41:21 -0500175 u8 ctrl[2];
Bartosz Golaszewskib3ff7fd2020-09-14 17:45:55 +0200176 int need_clear = 0, err;
Akshay Bhated13d892015-12-03 14:41:21 -0500177
178 /* Initialize reserved registers as specified in datasheet */
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +0200179 err = regmap_write(rx8010->regs, RX8010_RESV17, 0xD8);
180 if (err)
Akshay Bhated13d892015-12-03 14:41:21 -0500181 return err;
182
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +0200183 err = regmap_write(rx8010->regs, RX8010_RESV30, 0x00);
184 if (err)
Akshay Bhated13d892015-12-03 14:41:21 -0500185 return err;
186
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +0200187 err = regmap_write(rx8010->regs, RX8010_RESV31, 0x08);
188 if (err)
Akshay Bhated13d892015-12-03 14:41:21 -0500189 return err;
190
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +0200191 err = regmap_write(rx8010->regs, RX8010_IRQ, 0x00);
192 if (err)
Akshay Bhated13d892015-12-03 14:41:21 -0500193 return err;
194
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +0200195 err = regmap_bulk_read(rx8010->regs, RX8010_FLAG, ctrl, 2);
196 if (err)
197 return err;
Akshay Bhated13d892015-12-03 14:41:21 -0500198
199 if (ctrl[0] & RX8010_FLAG_VLF)
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +0200200 dev_warn(dev, "Frequency stop was detected\n");
Akshay Bhated13d892015-12-03 14:41:21 -0500201
202 if (ctrl[0] & RX8010_FLAG_AF) {
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +0200203 dev_warn(dev, "Alarm was detected\n");
Akshay Bhated13d892015-12-03 14:41:21 -0500204 need_clear = 1;
205 }
206
207 if (ctrl[0] & RX8010_FLAG_TF)
208 need_clear = 1;
209
210 if (ctrl[0] & RX8010_FLAG_UF)
211 need_clear = 1;
212
213 if (need_clear) {
214 ctrl[0] &= ~(RX8010_FLAG_AF | RX8010_FLAG_TF | RX8010_FLAG_UF);
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +0200215 err = regmap_write(rx8010->regs, RX8010_FLAG, ctrl[0]);
216 if (err)
Akshay Bhated13d892015-12-03 14:41:21 -0500217 return err;
218 }
219
220 rx8010->ctrlreg = (ctrl[1] & ~RX8010_CTRL_TEST);
221
Akshay Bhat804a6cf2017-11-08 14:58:14 -0500222 return 0;
Akshay Bhated13d892015-12-03 14:41:21 -0500223}
224
225static int rx8010_read_alarm(struct device *dev, struct rtc_wkalrm *t)
226{
227 struct rx8010_data *rx8010 = dev_get_drvdata(dev);
Akshay Bhated13d892015-12-03 14:41:21 -0500228 u8 alarmvals[3];
Bartosz Golaszewski75677972020-09-14 17:45:51 +0200229 int flagreg, err;
Akshay Bhated13d892015-12-03 14:41:21 -0500230
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +0200231 err = regmap_bulk_read(rx8010->regs, RX8010_ALMIN, alarmvals, 3);
232 if (err)
233 return err;
Akshay Bhated13d892015-12-03 14:41:21 -0500234
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +0200235 err = regmap_read(rx8010->regs, RX8010_FLAG, &flagreg);
236 if (err)
237 return err;
Akshay Bhated13d892015-12-03 14:41:21 -0500238
239 t->time.tm_sec = 0;
240 t->time.tm_min = bcd2bin(alarmvals[0] & 0x7f);
241 t->time.tm_hour = bcd2bin(alarmvals[1] & 0x3f);
242
Uwe Kleine-König56d86a72016-06-28 10:43:45 +0200243 if (!(alarmvals[2] & RX8010_ALARM_AE))
Akshay Bhated13d892015-12-03 14:41:21 -0500244 t->time.tm_mday = bcd2bin(alarmvals[2] & 0x7f);
245
Akshay Bhated13d892015-12-03 14:41:21 -0500246 t->enabled = !!(rx8010->ctrlreg & RX8010_CTRL_AIE);
247 t->pending = (flagreg & RX8010_FLAG_AF) && t->enabled;
248
Akshay Bhat804a6cf2017-11-08 14:58:14 -0500249 return 0;
Akshay Bhated13d892015-12-03 14:41:21 -0500250}
251
252static int rx8010_set_alarm(struct device *dev, struct rtc_wkalrm *t)
253{
Akshay Bhated13d892015-12-03 14:41:21 -0500254 struct rx8010_data *rx8010 = dev_get_drvdata(dev);
255 u8 alarmvals[3];
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +0200256 int err;
Akshay Bhated13d892015-12-03 14:41:21 -0500257
258 if (rx8010->ctrlreg & (RX8010_CTRL_AIE | RX8010_CTRL_UIE)) {
259 rx8010->ctrlreg &= ~(RX8010_CTRL_AIE | RX8010_CTRL_UIE);
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +0200260 err = regmap_write(rx8010->regs, RX8010_CTRL, rx8010->ctrlreg);
261 if (err)
Akshay Bhated13d892015-12-03 14:41:21 -0500262 return err;
Akshay Bhated13d892015-12-03 14:41:21 -0500263 }
264
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +0200265 err = regmap_clear_bits(rx8010->regs, RX8010_FLAG, RX8010_FLAG_AF);
266 if (err)
Akshay Bhated13d892015-12-03 14:41:21 -0500267 return err;
268
269 alarmvals[0] = bin2bcd(t->time.tm_min);
270 alarmvals[1] = bin2bcd(t->time.tm_hour);
271 alarmvals[2] = bin2bcd(t->time.tm_mday);
272
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +0200273 err = regmap_bulk_write(rx8010->regs, RX8010_ALMIN, alarmvals, 2);
274 if (err)
Akshay Bhated13d892015-12-03 14:41:21 -0500275 return err;
276
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +0200277 err = regmap_clear_bits(rx8010->regs, RX8010_EXT, RX8010_EXT_WADA);
278 if (err)
Akshay Bhated13d892015-12-03 14:41:21 -0500279 return err;
280
281 if (alarmvals[2] == 0)
282 alarmvals[2] |= RX8010_ALARM_AE;
283
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +0200284 err = regmap_write(rx8010->regs, RX8010_ALWDAY, alarmvals[2]);
285 if (err)
Akshay Bhated13d892015-12-03 14:41:21 -0500286 return err;
287
288 if (t->enabled) {
289 if (rx8010->rtc->uie_rtctimer.enabled)
290 rx8010->ctrlreg |= RX8010_CTRL_UIE;
291 if (rx8010->rtc->aie_timer.enabled)
292 rx8010->ctrlreg |=
293 (RX8010_CTRL_AIE | RX8010_CTRL_UIE);
294
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +0200295 err = regmap_write(rx8010->regs, RX8010_CTRL, rx8010->ctrlreg);
296 if (err)
Akshay Bhated13d892015-12-03 14:41:21 -0500297 return err;
298 }
299
300 return 0;
301}
302
303static int rx8010_alarm_irq_enable(struct device *dev,
304 unsigned int enabled)
305{
Akshay Bhated13d892015-12-03 14:41:21 -0500306 struct rx8010_data *rx8010 = dev_get_drvdata(dev);
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +0200307 int err;
Akshay Bhated13d892015-12-03 14:41:21 -0500308 u8 ctrl;
Akshay Bhated13d892015-12-03 14:41:21 -0500309
310 ctrl = rx8010->ctrlreg;
311
312 if (enabled) {
313 if (rx8010->rtc->uie_rtctimer.enabled)
314 ctrl |= RX8010_CTRL_UIE;
315 if (rx8010->rtc->aie_timer.enabled)
316 ctrl |= (RX8010_CTRL_AIE | RX8010_CTRL_UIE);
317 } else {
318 if (!rx8010->rtc->uie_rtctimer.enabled)
319 ctrl &= ~RX8010_CTRL_UIE;
320 if (!rx8010->rtc->aie_timer.enabled)
321 ctrl &= ~RX8010_CTRL_AIE;
322 }
323
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +0200324 err = regmap_clear_bits(rx8010->regs, RX8010_FLAG, RX8010_FLAG_AF);
325 if (err)
Akshay Bhated13d892015-12-03 14:41:21 -0500326 return err;
327
328 if (ctrl != rx8010->ctrlreg) {
329 rx8010->ctrlreg = ctrl;
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +0200330 err = regmap_write(rx8010->regs, RX8010_CTRL, rx8010->ctrlreg);
331 if (err)
Akshay Bhated13d892015-12-03 14:41:21 -0500332 return err;
333 }
334
335 return 0;
336}
337
338static int rx8010_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
339{
Akshay Bhated13d892015-12-03 14:41:21 -0500340 struct rx8010_data *rx8010 = dev_get_drvdata(dev);
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +0200341 int tmp, flagreg, err;
Akshay Bhated13d892015-12-03 14:41:21 -0500342
343 switch (cmd) {
344 case RTC_VL_READ:
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +0200345 err = regmap_read(rx8010->regs, RX8010_FLAG, &flagreg);
346 if (err)
347 return err;
Akshay Bhated13d892015-12-03 14:41:21 -0500348
Alexandre Belloni8049c112019-12-14 23:02:59 +0100349 tmp = flagreg & RX8010_FLAG_VLF ? RTC_VL_DATA_INVALID : 0;
350 return put_user(tmp, (unsigned int __user *)arg);
Akshay Bhated13d892015-12-03 14:41:21 -0500351
Akshay Bhated13d892015-12-03 14:41:21 -0500352 default:
353 return -ENOIOCTLCMD;
354 }
355}
356
Alexandre Belloniaaaea292021-01-11 00:17:44 +0100357static const struct rtc_class_ops rx8010_rtc_ops = {
Bartosz Golaszewskid3b14292020-09-14 17:45:48 +0200358 .read_time = rx8010_get_time,
359 .set_time = rx8010_set_time,
360 .ioctl = rx8010_ioctl,
361 .read_alarm = rx8010_read_alarm,
362 .set_alarm = rx8010_set_alarm,
363 .alarm_irq_enable = rx8010_alarm_irq_enable,
364};
365
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +0200366static const struct regmap_config rx8010_regmap_config = {
367 .name = "rx8010-rtc",
368 .reg_bits = 8,
369 .val_bits = 8,
370};
371
Bartosz Golaszewskicee015d2020-09-14 17:45:59 +0200372static int rx8010_probe(struct i2c_client *client)
Akshay Bhated13d892015-12-03 14:41:21 -0500373{
Bartosz Golaszewski955a1232020-09-14 17:45:56 +0200374 struct device *dev = &client->dev;
Akshay Bhated13d892015-12-03 14:41:21 -0500375 struct rx8010_data *rx8010;
376 int err = 0;
377
Bartosz Golaszewski666f2142020-09-14 17:45:57 +0200378 rx8010 = devm_kzalloc(dev, sizeof(*rx8010), GFP_KERNEL);
Akshay Bhated13d892015-12-03 14:41:21 -0500379 if (!rx8010)
380 return -ENOMEM;
381
Akshay Bhated13d892015-12-03 14:41:21 -0500382 i2c_set_clientdata(client, rx8010);
383
Bartosz Golaszewski9868bc12020-09-14 17:46:00 +0200384 rx8010->regs = devm_regmap_init_i2c(client, &rx8010_regmap_config);
385 if (IS_ERR(rx8010->regs))
386 return PTR_ERR(rx8010->regs);
387
Bartosz Golaszewskiba1bcaf2020-09-17 13:46:56 +0200388 err = rx8010_init(dev);
Akshay Bhated13d892015-12-03 14:41:21 -0500389 if (err)
390 return err;
391
Bartosz Golaszewski0ce62772020-09-14 17:45:58 +0200392 rx8010->rtc = devm_rtc_allocate_device(dev);
393 if (IS_ERR(rx8010->rtc))
394 return PTR_ERR(rx8010->rtc);
395
Akshay Bhated13d892015-12-03 14:41:21 -0500396 if (client->irq > 0) {
Bartosz Golaszewski955a1232020-09-14 17:45:56 +0200397 dev_info(dev, "IRQ %d supplied\n", client->irq);
398 err = devm_request_threaded_irq(dev, client->irq, NULL,
Akshay Bhated13d892015-12-03 14:41:21 -0500399 rx8010_irq_1_handler,
400 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
401 "rx8010", client);
Akshay Bhated13d892015-12-03 14:41:21 -0500402 if (err) {
Bartosz Golaszewski955a1232020-09-14 17:45:56 +0200403 dev_err(dev, "unable to request IRQ\n");
Bartosz Golaszewskid3b14292020-09-14 17:45:48 +0200404 return err;
Akshay Bhated13d892015-12-03 14:41:21 -0500405 }
Bartosz Golaszewskid3b14292020-09-14 17:45:48 +0200406 } else {
Alexandre Belloniaaaea292021-01-11 00:17:44 +0100407 clear_bit(RTC_FEATURE_ALARM, rx8010->rtc->features);
Akshay Bhated13d892015-12-03 14:41:21 -0500408 }
409
Alexandre Belloniaaaea292021-01-11 00:17:44 +0100410 rx8010->rtc->ops = &rx8010_rtc_ops;
Akshay Bhated13d892015-12-03 14:41:21 -0500411 rx8010->rtc->max_user_freq = 1;
Bartosz Golaszewski2fc1af32020-09-14 17:46:01 +0200412 rx8010->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
413 rx8010->rtc->range_max = RTC_TIMESTAMP_END_2099;
Akshay Bhated13d892015-12-03 14:41:21 -0500414
Bartosz Golaszewskifdcfd852020-11-09 17:34:08 +0100415 return devm_rtc_register_device(rx8010->rtc);
Akshay Bhated13d892015-12-03 14:41:21 -0500416}
417
418static struct i2c_driver rx8010_driver = {
419 .driver = {
420 .name = "rtc-rx8010",
Javier Martinez Canillas81b779c2017-03-03 11:29:16 -0300421 .of_match_table = of_match_ptr(rx8010_of_match),
Akshay Bhated13d892015-12-03 14:41:21 -0500422 },
Bartosz Golaszewskicee015d2020-09-14 17:45:59 +0200423 .probe_new = rx8010_probe,
Akshay Bhated13d892015-12-03 14:41:21 -0500424 .id_table = rx8010_id,
425};
426
427module_i2c_driver(rx8010_driver);
428
429MODULE_AUTHOR("Akshay Bhat <akshay.bhat@timesys.com>");
430MODULE_DESCRIPTION("Epson RX8010SJ RTC driver");
431MODULE_LICENSE("GPL v2");