blob: 52683eda1da28768e8dd8167537f96815e085fe0 [file] [log] [blame]
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -07001/*
2 * Driver for Epson's RTC module RX-8025 SA/NB
3 *
4 * Copyright (C) 2009 Wolfgang Grandegger <wg@grandegger.com>
5 *
6 * Copyright (C) 2005 by Digi International Inc.
7 * All rights reserved.
8 *
9 * Modified by fengjh at rising.com.cn
10 * <http://lists.lm-sensors.org/mailman/listinfo/lm-sensors>
11 * 2006.11
12 *
13 * Code cleanup by Sergei Poselenov, <sposelenov@emcraft.com>
14 * Converted to new style by Wolfgang Grandegger <wg@grandegger.com>
15 * Alarm and periodic interrupt added by Dmitry Rakhchev <rda@emcraft.com>
16 *
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * version 2 as published by the Free Software Foundation.
20 */
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -070021#include <linux/bcd.h>
Alexandre Belloni2ddd1862015-07-25 11:50:22 +020022#include <linux/bitops.h>
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -070023#include <linux/i2c.h>
Alexandre Belloni15d3bdc2015-07-24 15:50:23 +020024#include <linux/kernel.h>
25#include <linux/module.h>
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -070026#include <linux/rtc.h>
27
28/* Register definitions */
29#define RX8025_REG_SEC 0x00
30#define RX8025_REG_MIN 0x01
31#define RX8025_REG_HOUR 0x02
32#define RX8025_REG_WDAY 0x03
33#define RX8025_REG_MDAY 0x04
34#define RX8025_REG_MONTH 0x05
35#define RX8025_REG_YEAR 0x06
36#define RX8025_REG_DIGOFF 0x07
37#define RX8025_REG_ALWMIN 0x08
38#define RX8025_REG_ALWHOUR 0x09
39#define RX8025_REG_ALWWDAY 0x0a
40#define RX8025_REG_ALDMIN 0x0b
41#define RX8025_REG_ALDHOUR 0x0c
42/* 0x0d is reserved */
43#define RX8025_REG_CTRL1 0x0e
44#define RX8025_REG_CTRL2 0x0f
45
46#define RX8025_BIT_CTRL1_CT (7 << 0)
47/* 1 Hz periodic level irq */
48#define RX8025_BIT_CTRL1_CT_1HZ 4
Alexandre Belloni2ddd1862015-07-25 11:50:22 +020049#define RX8025_BIT_CTRL1_TEST BIT(3)
50#define RX8025_BIT_CTRL1_1224 BIT(5)
51#define RX8025_BIT_CTRL1_DALE BIT(6)
52#define RX8025_BIT_CTRL1_WALE BIT(7)
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -070053
Alexandre Belloni2ddd1862015-07-25 11:50:22 +020054#define RX8025_BIT_CTRL2_DAFG BIT(0)
55#define RX8025_BIT_CTRL2_WAFG BIT(1)
56#define RX8025_BIT_CTRL2_CTFG BIT(2)
57#define RX8025_BIT_CTRL2_PON BIT(4)
58#define RX8025_BIT_CTRL2_XST BIT(5)
59#define RX8025_BIT_CTRL2_VDET BIT(6)
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -070060
61/* Clock precision adjustment */
62#define RX8025_ADJ_RESOLUTION 3050 /* in ppb */
63#define RX8025_ADJ_DATA_MAX 62
64#define RX8025_ADJ_DATA_MIN -62
65
66static const struct i2c_device_id rx8025_id[] = {
67 { "rx8025", 0 },
68 { }
69};
70MODULE_DEVICE_TABLE(i2c, rx8025_id);
71
72struct rx8025_data {
73 struct i2c_client *client;
74 struct rtc_device *rtc;
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -070075 u8 ctrl1;
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -070076};
77
78static int rx8025_read_reg(struct i2c_client *client, int number, u8 *value)
79{
80 int ret = i2c_smbus_read_byte_data(client, (number << 4) | 0x08);
81
82 if (ret < 0) {
83 dev_err(&client->dev, "Unable to read register #%d\n", number);
84 return ret;
85 }
86
87 *value = ret;
88 return 0;
89}
90
91static int rx8025_read_regs(struct i2c_client *client,
92 int number, u8 length, u8 *values)
93{
94 int ret = i2c_smbus_read_i2c_block_data(client, (number << 4) | 0x08,
95 length, values);
96
97 if (ret != length) {
98 dev_err(&client->dev, "Unable to read registers #%d..#%d\n",
99 number, number + length - 1);
100 return ret < 0 ? ret : -EIO;
101 }
102
103 return 0;
104}
105
106static int rx8025_write_reg(struct i2c_client *client, int number, u8 value)
107{
108 int ret = i2c_smbus_write_byte_data(client, number << 4, value);
109
110 if (ret)
111 dev_err(&client->dev, "Unable to write register #%d\n",
112 number);
113
114 return ret;
115}
116
117static int rx8025_write_regs(struct i2c_client *client,
118 int number, u8 length, u8 *values)
119{
120 int ret = i2c_smbus_write_i2c_block_data(client, (number << 4) | 0x08,
121 length, values);
122
123 if (ret)
124 dev_err(&client->dev, "Unable to write registers #%d..#%d\n",
125 number, number + length - 1);
126
127 return ret;
128}
129
Alexandre Bellonib6a57c92015-07-24 15:59:43 +0200130static irqreturn_t rx8025_handle_irq(int irq, void *dev_id)
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -0700131{
132 struct i2c_client *client = dev_id;
133 struct rx8025_data *rx8025 = i2c_get_clientdata(client);
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -0700134 u8 status;
135
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -0700136 if (rx8025_read_reg(client, RX8025_REG_CTRL2, &status))
137 goto out;
138
139 if (!(status & RX8025_BIT_CTRL2_XST))
140 dev_warn(&client->dev, "Oscillation stop was detected,"
141 "you may have to readjust the clock\n");
142
143 if (status & RX8025_BIT_CTRL2_CTFG) {
144 /* periodic */
145 status &= ~RX8025_BIT_CTRL2_CTFG;
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -0700146 rtc_update_irq(rx8025->rtc, 1, RTC_PF | RTC_IRQF);
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -0700147 }
148
149 if (status & RX8025_BIT_CTRL2_DAFG) {
150 /* alarm */
151 status &= RX8025_BIT_CTRL2_DAFG;
152 if (rx8025_write_reg(client, RX8025_REG_CTRL1,
153 rx8025->ctrl1 & ~RX8025_BIT_CTRL1_DALE))
154 goto out;
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -0700155 rtc_update_irq(rx8025->rtc, 1, RTC_AF | RTC_IRQF);
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -0700156 }
157
158 /* acknowledge IRQ */
159 rx8025_write_reg(client, RX8025_REG_CTRL2,
160 status | RX8025_BIT_CTRL2_XST);
161
162out:
Alexandre Bellonib6a57c92015-07-24 15:59:43 +0200163 return IRQ_HANDLED;
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -0700164}
165
166static int rx8025_get_time(struct device *dev, struct rtc_time *dt)
167{
168 struct rx8025_data *rx8025 = dev_get_drvdata(dev);
169 u8 date[7];
170 int err;
171
172 err = rx8025_read_regs(rx8025->client, RX8025_REG_SEC, 7, date);
173 if (err)
174 return err;
175
176 dev_dbg(dev, "%s: read 0x%02x 0x%02x "
177 "0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n", __func__,
178 date[0], date[1], date[2], date[3], date[4],
179 date[5], date[6]);
180
181 dt->tm_sec = bcd2bin(date[RX8025_REG_SEC] & 0x7f);
182 dt->tm_min = bcd2bin(date[RX8025_REG_MIN] & 0x7f);
183 if (rx8025->ctrl1 & RX8025_BIT_CTRL1_1224)
184 dt->tm_hour = bcd2bin(date[RX8025_REG_HOUR] & 0x3f);
185 else
186 dt->tm_hour = bcd2bin(date[RX8025_REG_HOUR] & 0x1f) % 12
187 + (date[RX8025_REG_HOUR] & 0x20 ? 12 : 0);
188
189 dt->tm_mday = bcd2bin(date[RX8025_REG_MDAY] & 0x3f);
190 dt->tm_mon = bcd2bin(date[RX8025_REG_MONTH] & 0x1f) - 1;
191 dt->tm_year = bcd2bin(date[RX8025_REG_YEAR]);
192
193 if (dt->tm_year < 70)
194 dt->tm_year += 100;
195
196 dev_dbg(dev, "%s: date %ds %dm %dh %dmd %dm %dy\n", __func__,
197 dt->tm_sec, dt->tm_min, dt->tm_hour,
198 dt->tm_mday, dt->tm_mon, dt->tm_year);
199
200 return rtc_valid_tm(dt);
201}
202
203static int rx8025_set_time(struct device *dev, struct rtc_time *dt)
204{
205 struct rx8025_data *rx8025 = dev_get_drvdata(dev);
206 u8 date[7];
207
208 /*
209 * BUG: The HW assumes every year that is a multiple of 4 to be a leap
210 * year. Next time this is wrong is 2100, which will not be a leap
211 * year.
212 */
213
214 /*
215 * Here the read-only bits are written as "0". I'm not sure if that
216 * is sound.
217 */
218 date[RX8025_REG_SEC] = bin2bcd(dt->tm_sec);
219 date[RX8025_REG_MIN] = bin2bcd(dt->tm_min);
220 if (rx8025->ctrl1 & RX8025_BIT_CTRL1_1224)
221 date[RX8025_REG_HOUR] = bin2bcd(dt->tm_hour);
222 else
223 date[RX8025_REG_HOUR] = (dt->tm_hour >= 12 ? 0x20 : 0)
224 | bin2bcd((dt->tm_hour + 11) % 12 + 1);
225
226 date[RX8025_REG_WDAY] = bin2bcd(dt->tm_wday);
227 date[RX8025_REG_MDAY] = bin2bcd(dt->tm_mday);
228 date[RX8025_REG_MONTH] = bin2bcd(dt->tm_mon + 1);
229 date[RX8025_REG_YEAR] = bin2bcd(dt->tm_year % 100);
230
231 dev_dbg(dev,
232 "%s: write 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
233 __func__,
234 date[0], date[1], date[2], date[3], date[4], date[5], date[6]);
235
236 return rx8025_write_regs(rx8025->client, RX8025_REG_SEC, 7, date);
237}
238
239static int rx8025_init_client(struct i2c_client *client, int *need_reset)
240{
241 struct rx8025_data *rx8025 = i2c_get_clientdata(client);
242 u8 ctrl[2], ctrl2;
243 int need_clear = 0;
244 int err;
245
246 err = rx8025_read_regs(rx8025->client, RX8025_REG_CTRL1, 2, ctrl);
247 if (err)
248 goto out;
249
250 /* Keep test bit zero ! */
251 rx8025->ctrl1 = ctrl[0] & ~RX8025_BIT_CTRL1_TEST;
252
253 if (ctrl[1] & RX8025_BIT_CTRL2_PON) {
254 dev_warn(&client->dev, "power-on reset was detected, "
255 "you may have to readjust the clock\n");
256 *need_reset = 1;
257 }
258
259 if (ctrl[1] & RX8025_BIT_CTRL2_VDET) {
260 dev_warn(&client->dev, "a power voltage drop was detected, "
261 "you may have to readjust the clock\n");
262 *need_reset = 1;
263 }
264
265 if (!(ctrl[1] & RX8025_BIT_CTRL2_XST)) {
266 dev_warn(&client->dev, "Oscillation stop was detected,"
267 "you may have to readjust the clock\n");
268 *need_reset = 1;
269 }
270
271 if (ctrl[1] & (RX8025_BIT_CTRL2_DAFG | RX8025_BIT_CTRL2_WAFG)) {
272 dev_warn(&client->dev, "Alarm was detected\n");
273 need_clear = 1;
274 }
275
276 if (!(ctrl[1] & RX8025_BIT_CTRL2_CTFG))
277 need_clear = 1;
278
279 if (*need_reset || need_clear) {
280 ctrl2 = ctrl[0];
281 ctrl2 &= ~(RX8025_BIT_CTRL2_PON | RX8025_BIT_CTRL2_VDET |
282 RX8025_BIT_CTRL2_CTFG | RX8025_BIT_CTRL2_WAFG |
283 RX8025_BIT_CTRL2_DAFG);
284 ctrl2 |= RX8025_BIT_CTRL2_XST;
285
286 err = rx8025_write_reg(client, RX8025_REG_CTRL2, ctrl2);
287 }
288out:
289 return err;
290}
291
292/* Alarm support */
293static int rx8025_read_alarm(struct device *dev, struct rtc_wkalrm *t)
294{
295 struct rx8025_data *rx8025 = dev_get_drvdata(dev);
296 struct i2c_client *client = rx8025->client;
297 u8 ctrl2, ald[2];
298 int err;
299
300 if (client->irq <= 0)
301 return -EINVAL;
302
303 err = rx8025_read_regs(client, RX8025_REG_ALDMIN, 2, ald);
304 if (err)
305 return err;
306
307 err = rx8025_read_reg(client, RX8025_REG_CTRL2, &ctrl2);
308 if (err)
309 return err;
310
311 dev_dbg(dev, "%s: read alarm 0x%02x 0x%02x ctrl2 %02x\n",
312 __func__, ald[0], ald[1], ctrl2);
313
314 /* Hardware alarms precision is 1 minute! */
315 t->time.tm_sec = 0;
316 t->time.tm_min = bcd2bin(ald[0] & 0x7f);
317 if (rx8025->ctrl1 & RX8025_BIT_CTRL1_1224)
318 t->time.tm_hour = bcd2bin(ald[1] & 0x3f);
319 else
320 t->time.tm_hour = bcd2bin(ald[1] & 0x1f) % 12
321 + (ald[1] & 0x20 ? 12 : 0);
322
323 t->time.tm_wday = -1;
324 t->time.tm_mday = -1;
325 t->time.tm_mon = -1;
326 t->time.tm_year = -1;
327
328 dev_dbg(dev, "%s: date: %ds %dm %dh %dmd %dm %dy\n",
329 __func__,
330 t->time.tm_sec, t->time.tm_min, t->time.tm_hour,
331 t->time.tm_mday, t->time.tm_mon, t->time.tm_year);
332 t->enabled = !!(rx8025->ctrl1 & RX8025_BIT_CTRL1_DALE);
333 t->pending = (ctrl2 & RX8025_BIT_CTRL2_DAFG) && t->enabled;
334
335 return err;
336}
337
338static int rx8025_set_alarm(struct device *dev, struct rtc_wkalrm *t)
339{
340 struct i2c_client *client = to_i2c_client(dev);
341 struct rx8025_data *rx8025 = dev_get_drvdata(dev);
342 u8 ald[2];
343 int err;
344
345 if (client->irq <= 0)
346 return -EINVAL;
347
348 /* Hardware alarm precision is 1 minute! */
349 ald[0] = bin2bcd(t->time.tm_min);
350 if (rx8025->ctrl1 & RX8025_BIT_CTRL1_1224)
351 ald[1] = bin2bcd(t->time.tm_hour);
352 else
353 ald[1] = (t->time.tm_hour >= 12 ? 0x20 : 0)
354 | bin2bcd((t->time.tm_hour + 11) % 12 + 1);
355
356 dev_dbg(dev, "%s: write 0x%02x 0x%02x\n", __func__, ald[0], ald[1]);
357
358 if (rx8025->ctrl1 & RX8025_BIT_CTRL1_DALE) {
359 rx8025->ctrl1 &= ~RX8025_BIT_CTRL1_DALE;
360 err = rx8025_write_reg(rx8025->client, RX8025_REG_CTRL1,
361 rx8025->ctrl1);
362 if (err)
363 return err;
364 }
365 err = rx8025_write_regs(rx8025->client, RX8025_REG_ALDMIN, 2, ald);
366 if (err)
367 return err;
368
369 if (t->enabled) {
370 rx8025->ctrl1 |= RX8025_BIT_CTRL1_DALE;
371 err = rx8025_write_reg(rx8025->client, RX8025_REG_CTRL1,
372 rx8025->ctrl1);
373 if (err)
374 return err;
375 }
376
377 return 0;
378}
379
380static int rx8025_alarm_irq_enable(struct device *dev, unsigned int enabled)
381{
382 struct rx8025_data *rx8025 = dev_get_drvdata(dev);
383 u8 ctrl1;
384 int err;
385
386 ctrl1 = rx8025->ctrl1;
387 if (enabled)
388 ctrl1 |= RX8025_BIT_CTRL1_DALE;
389 else
390 ctrl1 &= ~RX8025_BIT_CTRL1_DALE;
391
392 if (ctrl1 != rx8025->ctrl1) {
393 rx8025->ctrl1 = ctrl1;
394 err = rx8025_write_reg(rx8025->client, RX8025_REG_CTRL1,
395 rx8025->ctrl1);
396 if (err)
397 return err;
398 }
399 return 0;
400}
401
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -0700402static struct rtc_class_ops rx8025_rtc_ops = {
403 .read_time = rx8025_get_time,
404 .set_time = rx8025_set_time,
405 .read_alarm = rx8025_read_alarm,
406 .set_alarm = rx8025_set_alarm,
407 .alarm_irq_enable = rx8025_alarm_irq_enable,
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -0700408};
409
410/*
411 * Clock precision adjustment support
412 *
413 * According to the RX8025 SA/NB application manual the frequency and
Thomas Weberb770ffd2010-07-19 08:22:43 +0200414 * temperature characteristics can be approximated using the following
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -0700415 * equation:
416 *
417 * df = a * (ut - t)**2
418 *
419 * df: Frequency deviation in any temperature
420 * a : Coefficient = (-35 +-5) * 10**-9
421 * ut: Ultimate temperature in degree = +25 +-5 degree
422 * t : Any temperature in degree
423 *
424 * Note that the clock adjustment in ppb must be entered (which is
425 * the negative value of the deviation).
426 */
427static int rx8025_get_clock_adjust(struct device *dev, int *adj)
428{
429 struct i2c_client *client = to_i2c_client(dev);
430 u8 digoff;
431 int err;
432
433 err = rx8025_read_reg(client, RX8025_REG_DIGOFF, &digoff);
434 if (err)
435 return err;
436
437 *adj = digoff >= 64 ? digoff - 128 : digoff;
438 if (*adj > 0)
439 (*adj)--;
440 *adj *= -RX8025_ADJ_RESOLUTION;
441
442 return 0;
443}
444
445static int rx8025_set_clock_adjust(struct device *dev, int adj)
446{
447 struct i2c_client *client = to_i2c_client(dev);
448 u8 digoff;
449 int err;
450
451 adj /= -RX8025_ADJ_RESOLUTION;
452 if (adj > RX8025_ADJ_DATA_MAX)
453 adj = RX8025_ADJ_DATA_MAX;
454 else if (adj < RX8025_ADJ_DATA_MIN)
455 adj = RX8025_ADJ_DATA_MIN;
456 else if (adj > 0)
457 adj++;
458 else if (adj < 0)
459 adj += 128;
460 digoff = adj;
461
462 err = rx8025_write_reg(client, RX8025_REG_DIGOFF, digoff);
463 if (err)
464 return err;
465
466 dev_dbg(dev, "%s: write 0x%02x\n", __func__, digoff);
467
468 return 0;
469}
470
471static ssize_t rx8025_sysfs_show_clock_adjust(struct device *dev,
472 struct device_attribute *attr,
473 char *buf)
474{
475 int err, adj;
476
477 err = rx8025_get_clock_adjust(dev, &adj);
478 if (err)
479 return err;
480
481 return sprintf(buf, "%d\n", adj);
482}
483
484static ssize_t rx8025_sysfs_store_clock_adjust(struct device *dev,
485 struct device_attribute *attr,
486 const char *buf, size_t count)
487{
488 int adj, err;
489
490 if (sscanf(buf, "%i", &adj) != 1)
491 return -EINVAL;
492
493 err = rx8025_set_clock_adjust(dev, adj);
494
495 return err ? err : count;
496}
497
498static DEVICE_ATTR(clock_adjust_ppb, S_IRUGO | S_IWUSR,
499 rx8025_sysfs_show_clock_adjust,
500 rx8025_sysfs_store_clock_adjust);
501
502static int rx8025_sysfs_register(struct device *dev)
503{
504 return device_create_file(dev, &dev_attr_clock_adjust_ppb);
505}
506
507static void rx8025_sysfs_unregister(struct device *dev)
508{
509 device_remove_file(dev, &dev_attr_clock_adjust_ppb);
510}
511
Greg Kroah-Hartman5a167f42012-12-21 13:09:38 -0800512static int rx8025_probe(struct i2c_client *client,
513 const struct i2c_device_id *id)
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -0700514{
515 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
516 struct rx8025_data *rx8025;
Alexandre Bellonidbcce7c2015-07-24 16:12:10 +0200517 int err = 0, need_reset = 0;
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -0700518
519 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA
520 | I2C_FUNC_SMBUS_I2C_BLOCK)) {
521 dev_err(&adapter->dev,
522 "doesn't support required functionality\n");
Alexandre Bellonidbcce7c2015-07-24 16:12:10 +0200523 return -EIO;
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -0700524 }
525
Jingoo Hanfac42b42013-07-03 15:07:10 -0700526 rx8025 = devm_kzalloc(&client->dev, sizeof(*rx8025), GFP_KERNEL);
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -0700527 if (!rx8025) {
Alexandre Bellonidbcce7c2015-07-24 16:12:10 +0200528 return -ENOMEM;
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -0700529 }
530
531 rx8025->client = client;
532 i2c_set_clientdata(client, rx8025);
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -0700533
534 err = rx8025_init_client(client, &need_reset);
535 if (err)
Alexandre Bellonidbcce7c2015-07-24 16:12:10 +0200536 return err;
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -0700537
538 if (need_reset) {
539 struct rtc_time tm;
540 dev_info(&client->dev,
541 "bad conditions detected, resetting date\n");
542 rtc_time_to_tm(0, &tm); /* 1970/1/1 */
543 rx8025_set_time(&client->dev, &tm);
544 }
545
Jingoo Hanfac42b42013-07-03 15:07:10 -0700546 rx8025->rtc = devm_rtc_device_register(&client->dev, client->name,
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -0700547 &rx8025_rtc_ops, THIS_MODULE);
548 if (IS_ERR(rx8025->rtc)) {
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -0700549 dev_err(&client->dev, "unable to register the class device\n");
Alexandre Bellonidbcce7c2015-07-24 16:12:10 +0200550 return PTR_ERR(rx8025->rtc);
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -0700551 }
552
553 if (client->irq > 0) {
554 dev_info(&client->dev, "IRQ %d supplied\n", client->irq);
Alexandre Bellonif0b63a12015-07-24 16:07:30 +0200555 err = devm_request_threaded_irq(&client->dev, client->irq, NULL,
556 rx8025_handle_irq, 0, "rx8025",
557 client);
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -0700558 if (err) {
559 dev_err(&client->dev, "unable to request IRQ\n");
Alexandre Bellonidbcce7c2015-07-24 16:12:10 +0200560 return err;
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -0700561 }
562 }
563
564 rx8025->rtc->irq_freq = 1;
565 rx8025->rtc->max_user_freq = 1;
566
567 err = rx8025_sysfs_register(&client->dev);
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -0700568 return err;
569}
570
Greg Kroah-Hartman5a167f42012-12-21 13:09:38 -0800571static int rx8025_remove(struct i2c_client *client)
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -0700572{
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -0700573 rx8025_sysfs_unregister(&client->dev);
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -0700574 return 0;
575}
576
577static struct i2c_driver rx8025_driver = {
578 .driver = {
579 .name = "rtc-rx8025",
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -0700580 },
581 .probe = rx8025_probe,
Greg Kroah-Hartman5a167f42012-12-21 13:09:38 -0800582 .remove = rx8025_remove,
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -0700583 .id_table = rx8025_id,
584};
585
Axel Lin0abc9202012-03-23 15:02:31 -0700586module_i2c_driver(rx8025_driver);
Wolfgang Grandegger3c2b9072009-06-17 16:26:11 -0700587
588MODULE_AUTHOR("Wolfgang Grandegger <wg@grandegger.com>");
589MODULE_DESCRIPTION("RX-8025 SA/NB RTC driver");
590MODULE_LICENSE("GPL");