blob: 036e5fc148d4f18ae8a71c3605ca891f98e4f79e [file] [log] [blame]
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -07001/*
2 * Intersil ISL1208 rtc class driver
3 *
4 * Copyright 2005,2006 Hebert Valerio Riedel <hvr@gnu.org>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 *
11 */
12
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -070013#include <linux/bcd.h>
Alexandre Belloni4b3a6a32018-09-19 03:13:22 +020014#include <linux/i2c.h>
15#include <linux/module.h>
Trent Piepho5909b872019-02-12 02:34:04 +000016#include <linux/of_device.h>
Denis Osterland9ece7cd2018-07-24 11:31:21 +000017#include <linux/of_irq.h>
Alexandre Belloni4b3a6a32018-09-19 03:13:22 +020018#include <linux/rtc.h>
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -070019
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -070020/* Register map */
21/* rtc section */
22#define ISL1208_REG_SC 0x00
23#define ISL1208_REG_MN 0x01
24#define ISL1208_REG_HR 0x02
Alessandro Zummo9edae7b2008-04-28 02:11:53 -070025#define ISL1208_REG_HR_MIL (1<<7) /* 24h/12h mode */
26#define ISL1208_REG_HR_PM (1<<5) /* PM/AM bit in 12h mode */
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -070027#define ISL1208_REG_DT 0x03
28#define ISL1208_REG_MO 0x04
29#define ISL1208_REG_YR 0x05
30#define ISL1208_REG_DW 0x06
31#define ISL1208_RTC_SECTION_LEN 7
32
33/* control/status section */
34#define ISL1208_REG_SR 0x07
Alessandro Zummo9edae7b2008-04-28 02:11:53 -070035#define ISL1208_REG_SR_ARST (1<<7) /* auto reset */
36#define ISL1208_REG_SR_XTOSCB (1<<6) /* crystal oscillator */
37#define ISL1208_REG_SR_WRTC (1<<4) /* write rtc */
Michael Grzeschikdd35bdb2018-07-24 11:31:21 +000038#define ISL1208_REG_SR_EVT (1<<3) /* event */
Alessandro Zummo9edae7b2008-04-28 02:11:53 -070039#define ISL1208_REG_SR_ALM (1<<2) /* alarm */
40#define ISL1208_REG_SR_BAT (1<<1) /* battery */
41#define ISL1208_REG_SR_RTCF (1<<0) /* rtc fail */
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -070042#define ISL1208_REG_INT 0x08
Ryan Malloncf044f02011-03-22 16:34:53 -070043#define ISL1208_REG_INT_ALME (1<<6) /* alarm enable */
44#define ISL1208_REG_INT_IM (1<<7) /* interrupt/alarm mode */
Michael Grzeschikdd35bdb2018-07-24 11:31:21 +000045#define ISL1219_REG_EV 0x09
46#define ISL1219_REG_EV_EVEN (1<<4) /* event detection enable */
Denis Osterlandcfa30622018-07-24 11:31:21 +000047#define ISL1219_REG_EV_EVIENB (1<<7) /* event in pull-up disable */
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -070048#define ISL1208_REG_ATR 0x0a
49#define ISL1208_REG_DTR 0x0b
50
51/* alarm section */
52#define ISL1208_REG_SCA 0x0c
53#define ISL1208_REG_MNA 0x0d
54#define ISL1208_REG_HRA 0x0e
55#define ISL1208_REG_DTA 0x0f
56#define ISL1208_REG_MOA 0x10
57#define ISL1208_REG_DWA 0x11
58#define ISL1208_ALARM_SECTION_LEN 6
59
60/* user section */
61#define ISL1208_REG_USR1 0x12
62#define ISL1208_REG_USR2 0x13
63#define ISL1208_USR_SECTION_LEN 2
64
Michael Grzeschikdd35bdb2018-07-24 11:31:21 +000065/* event section */
66#define ISL1219_REG_SCT 0x14
67#define ISL1219_REG_MNT 0x15
68#define ISL1219_REG_HRT 0x16
69#define ISL1219_REG_DTT 0x17
70#define ISL1219_REG_MOT 0x18
71#define ISL1219_REG_YRT 0x19
72#define ISL1219_EVT_SECTION_LEN 6
73
Alessandro Zummo9edae7b2008-04-28 02:11:53 -070074static struct i2c_driver isl1208_driver;
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -070075
Michael Grzeschikdd35bdb2018-07-24 11:31:21 +000076/* ISL1208 various variants */
Trent Piepho5909b872019-02-12 02:34:04 +000077enum isl1208_id {
Michael Grzeschikdd35bdb2018-07-24 11:31:21 +000078 TYPE_ISL1208 = 0,
Trent Piepho5909b872019-02-12 02:34:04 +000079 TYPE_ISL1209,
Michael Grzeschikdd35bdb2018-07-24 11:31:21 +000080 TYPE_ISL1218,
81 TYPE_ISL1219,
Trent Piepho5909b872019-02-12 02:34:04 +000082 ISL_LAST_ID
Michael Grzeschikdd35bdb2018-07-24 11:31:21 +000083};
84
Trent Piepho5909b872019-02-12 02:34:04 +000085/* Chip capabilities table */
86static const struct isl1208_config {
87 const char name[8];
88 unsigned int nvmem_length;
89 unsigned has_tamper:1;
90 unsigned has_timestamp:1;
91} isl1208_configs[] = {
92 [TYPE_ISL1208] = { "isl1208", 2, false, false },
93 [TYPE_ISL1209] = { "isl1209", 2, true, false },
94 [TYPE_ISL1218] = { "isl1218", 8, false, false },
95 [TYPE_ISL1219] = { "isl1219", 2, true, true },
96};
97
98static const struct i2c_device_id isl1208_id[] = {
99 { "isl1208", TYPE_ISL1208 },
100 { "isl1209", TYPE_ISL1209 },
101 { "isl1218", TYPE_ISL1218 },
102 { "isl1219", TYPE_ISL1219 },
103 { }
104};
105MODULE_DEVICE_TABLE(i2c, isl1208_id);
106
107static const struct of_device_id isl1208_of_match[] = {
108 { .compatible = "isil,isl1208", .data = &isl1208_configs[TYPE_ISL1208] },
109 { .compatible = "isil,isl1209", .data = &isl1208_configs[TYPE_ISL1209] },
110 { .compatible = "isil,isl1218", .data = &isl1208_configs[TYPE_ISL1218] },
111 { .compatible = "isil,isl1219", .data = &isl1208_configs[TYPE_ISL1219] },
112 { }
113};
114MODULE_DEVICE_TABLE(of, isl1208_of_match);
115
Trent Piephoed3c52a2019-02-12 02:34:03 +0000116/* Device state */
117struct isl1208_state {
118 struct rtc_device *rtc;
Trent Piepho5909b872019-02-12 02:34:04 +0000119 const struct isl1208_config *config;
Trent Piephoed3c52a2019-02-12 02:34:03 +0000120};
121
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700122/* block read */
123static int
124isl1208_i2c_read_regs(struct i2c_client *client, u8 reg, u8 buf[],
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700125 unsigned len)
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700126{
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700127 int ret;
128
Michael Grzeschikdd35bdb2018-07-24 11:31:21 +0000129 WARN_ON(reg > ISL1219_REG_YRT);
130 WARN_ON(reg + len > ISL1219_REG_YRT + 1);
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700131
Trent Piephofacc23b2018-11-15 18:51:18 +0000132 ret = i2c_smbus_read_i2c_block_data(client, reg, len, buf);
133 return (ret < 0) ? ret : 0;
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700134}
135
136/* block write */
137static int
138isl1208_i2c_set_regs(struct i2c_client *client, u8 reg, u8 const buf[],
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700139 unsigned len)
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700140{
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700141 int ret;
142
Michael Grzeschikdd35bdb2018-07-24 11:31:21 +0000143 WARN_ON(reg > ISL1219_REG_YRT);
144 WARN_ON(reg + len > ISL1219_REG_YRT + 1);
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700145
Trent Piephofacc23b2018-11-15 18:51:18 +0000146 ret = i2c_smbus_write_i2c_block_data(client, reg, len, buf);
147 return (ret < 0) ? ret : 0;
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700148}
149
Adam Buchbinder48fc7f72012-09-19 21:48:00 -0400150/* simple check to see whether we have a isl1208 */
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700151static int
152isl1208_i2c_validate_client(struct i2c_client *client)
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700153{
154 u8 regs[ISL1208_RTC_SECTION_LEN] = { 0, };
155 u8 zero_mask[ISL1208_RTC_SECTION_LEN] = {
156 0x80, 0x80, 0x40, 0xc0, 0xe0, 0x00, 0xf8
157 };
158 int i;
159 int ret;
160
161 ret = isl1208_i2c_read_regs(client, 0, regs, ISL1208_RTC_SECTION_LEN);
162 if (ret < 0)
163 return ret;
164
165 for (i = 0; i < ISL1208_RTC_SECTION_LEN; ++i) {
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700166 if (regs[i] & zero_mask[i]) /* check if bits are cleared */
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700167 return -ENODEV;
168 }
169
170 return 0;
171}
172
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700173static int
174isl1208_i2c_get_sr(struct i2c_client *client)
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700175{
Sachin Kamatc91fd912013-11-12 15:10:26 -0800176 return i2c_smbus_read_byte_data(client, ISL1208_REG_SR);
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700177}
178
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700179static int
180isl1208_i2c_get_atr(struct i2c_client *client)
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700181{
182 int atr = i2c_smbus_read_byte_data(client, ISL1208_REG_ATR);
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700183 if (atr < 0)
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700184 return atr;
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700185
186 /* The 6bit value in the ATR register controls the load
187 * capacitance C_load * in steps of 0.25pF
188 *
189 * bit (1<<5) of the ATR register is inverted
190 *
191 * C_load(ATR=0x20) = 4.50pF
192 * C_load(ATR=0x00) = 12.50pF
193 * C_load(ATR=0x1f) = 20.25pF
194 *
195 */
196
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700197 atr &= 0x3f; /* mask out lsb */
198 atr ^= 1 << 5; /* invert 6th bit */
199 atr += 2 * 9; /* add offset of 4.5pF; unit[atr] = 0.25pF */
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700200
201 return atr;
202}
203
Trent Piephoc8c97a4f2019-01-02 16:00:17 +0000204/* returns adjustment value + 100 */
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700205static int
206isl1208_i2c_get_dtr(struct i2c_client *client)
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700207{
208 int dtr = i2c_smbus_read_byte_data(client, ISL1208_REG_DTR);
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700209 if (dtr < 0)
210 return -EIO;
211
212 /* dtr encodes adjustments of {-60,-40,-20,0,20,40,60} ppm */
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700213 dtr = ((dtr & 0x3) * 20) * (dtr & (1 << 2) ? -1 : 1);
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700214
Trent Piephoc8c97a4f2019-01-02 16:00:17 +0000215 return dtr + 100;
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700216}
217
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700218static int
219isl1208_i2c_get_usr(struct i2c_client *client)
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700220{
221 u8 buf[ISL1208_USR_SECTION_LEN] = { 0, };
222 int ret;
223
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700224 ret = isl1208_i2c_read_regs(client, ISL1208_REG_USR1, buf,
225 ISL1208_USR_SECTION_LEN);
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700226 if (ret < 0)
227 return ret;
228
229 return (buf[1] << 8) | buf[0];
230}
231
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700232static int
233isl1208_i2c_set_usr(struct i2c_client *client, u16 usr)
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700234{
235 u8 buf[ISL1208_USR_SECTION_LEN];
236
237 buf[0] = usr & 0xff;
238 buf[1] = (usr >> 8) & 0xff;
239
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700240 return isl1208_i2c_set_regs(client, ISL1208_REG_USR1, buf,
241 ISL1208_USR_SECTION_LEN);
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700242}
243
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700244static int
Ryan Malloncf044f02011-03-22 16:34:53 -0700245isl1208_rtc_toggle_alarm(struct i2c_client *client, int enable)
246{
247 int icr = i2c_smbus_read_byte_data(client, ISL1208_REG_INT);
248
249 if (icr < 0) {
250 dev_err(&client->dev, "%s: reading INT failed\n", __func__);
251 return icr;
252 }
253
254 if (enable)
255 icr |= ISL1208_REG_INT_ALME | ISL1208_REG_INT_IM;
256 else
257 icr &= ~(ISL1208_REG_INT_ALME | ISL1208_REG_INT_IM);
258
259 icr = i2c_smbus_write_byte_data(client, ISL1208_REG_INT, icr);
260 if (icr < 0) {
261 dev_err(&client->dev, "%s: writing INT failed\n", __func__);
262 return icr;
263 }
264
265 return 0;
266}
267
268static int
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700269isl1208_rtc_proc(struct device *dev, struct seq_file *seq)
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700270{
271 struct i2c_client *const client = to_i2c_client(dev);
272 int sr, dtr, atr, usr;
273
274 sr = isl1208_i2c_get_sr(client);
275 if (sr < 0) {
276 dev_err(&client->dev, "%s: reading SR failed\n", __func__);
277 return sr;
278 }
279
280 seq_printf(seq, "status_reg\t:%s%s%s%s%s%s (0x%.2x)\n",
281 (sr & ISL1208_REG_SR_RTCF) ? " RTCF" : "",
282 (sr & ISL1208_REG_SR_BAT) ? " BAT" : "",
283 (sr & ISL1208_REG_SR_ALM) ? " ALM" : "",
284 (sr & ISL1208_REG_SR_WRTC) ? " WRTC" : "",
285 (sr & ISL1208_REG_SR_XTOSCB) ? " XTOSCB" : "",
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700286 (sr & ISL1208_REG_SR_ARST) ? " ARST" : "", sr);
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700287
288 seq_printf(seq, "batt_status\t: %s\n",
289 (sr & ISL1208_REG_SR_RTCF) ? "bad" : "okay");
290
291 dtr = isl1208_i2c_get_dtr(client);
Trent Piephoc8c97a4f2019-01-02 16:00:17 +0000292 if (dtr >= 0)
293 seq_printf(seq, "digital_trim\t: %d ppm\n", dtr - 100);
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700294
295 atr = isl1208_i2c_get_atr(client);
296 if (atr >= 0)
297 seq_printf(seq, "analog_trim\t: %d.%.2d pF\n",
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700298 atr >> 2, (atr & 0x3) * 25);
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700299
300 usr = isl1208_i2c_get_usr(client);
301 if (usr >= 0)
302 seq_printf(seq, "user_data\t: 0x%.4x\n", usr);
303
304 return 0;
305}
306
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700307static int
308isl1208_i2c_read_time(struct i2c_client *client, struct rtc_time *tm)
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700309{
310 int sr;
311 u8 regs[ISL1208_RTC_SECTION_LEN] = { 0, };
312
313 sr = isl1208_i2c_get_sr(client);
314 if (sr < 0) {
315 dev_err(&client->dev, "%s: reading SR failed\n", __func__);
316 return -EIO;
317 }
318
319 sr = isl1208_i2c_read_regs(client, 0, regs, ISL1208_RTC_SECTION_LEN);
320 if (sr < 0) {
321 dev_err(&client->dev, "%s: reading RTC section failed\n",
322 __func__);
323 return sr;
324 }
325
Adrian Bunkfe20ba72008-10-18 20:28:41 -0700326 tm->tm_sec = bcd2bin(regs[ISL1208_REG_SC]);
327 tm->tm_min = bcd2bin(regs[ISL1208_REG_MN]);
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700328
329 /* HR field has a more complex interpretation */
330 {
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700331 const u8 _hr = regs[ISL1208_REG_HR];
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700332 if (_hr & ISL1208_REG_HR_MIL) /* 24h format */
Adrian Bunkfe20ba72008-10-18 20:28:41 -0700333 tm->tm_hour = bcd2bin(_hr & 0x3f);
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700334 else {
335 /* 12h format */
Adrian Bunkfe20ba72008-10-18 20:28:41 -0700336 tm->tm_hour = bcd2bin(_hr & 0x1f);
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700337 if (_hr & ISL1208_REG_HR_PM) /* PM flag set */
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700338 tm->tm_hour += 12;
339 }
340 }
341
Adrian Bunkfe20ba72008-10-18 20:28:41 -0700342 tm->tm_mday = bcd2bin(regs[ISL1208_REG_DT]);
343 tm->tm_mon = bcd2bin(regs[ISL1208_REG_MO]) - 1; /* rtc starts at 1 */
344 tm->tm_year = bcd2bin(regs[ISL1208_REG_YR]) + 100;
345 tm->tm_wday = bcd2bin(regs[ISL1208_REG_DW]);
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700346
347 return 0;
348}
349
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700350static int
351isl1208_i2c_read_alarm(struct i2c_client *client, struct rtc_wkalrm *alarm)
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700352{
353 struct rtc_time *const tm = &alarm->time;
354 u8 regs[ISL1208_ALARM_SECTION_LEN] = { 0, };
Ryan Malloncf044f02011-03-22 16:34:53 -0700355 int icr, yr, sr = isl1208_i2c_get_sr(client);
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700356
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700357 if (sr < 0) {
358 dev_err(&client->dev, "%s: reading SR failed\n", __func__);
359 return sr;
360 }
361
362 sr = isl1208_i2c_read_regs(client, ISL1208_REG_SCA, regs,
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700363 ISL1208_ALARM_SECTION_LEN);
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700364 if (sr < 0) {
365 dev_err(&client->dev, "%s: reading alarm section failed\n",
366 __func__);
367 return sr;
368 }
369
370 /* MSB of each alarm register is an enable bit */
Adrian Bunkfe20ba72008-10-18 20:28:41 -0700371 tm->tm_sec = bcd2bin(regs[ISL1208_REG_SCA - ISL1208_REG_SCA] & 0x7f);
372 tm->tm_min = bcd2bin(regs[ISL1208_REG_MNA - ISL1208_REG_SCA] & 0x7f);
373 tm->tm_hour = bcd2bin(regs[ISL1208_REG_HRA - ISL1208_REG_SCA] & 0x3f);
374 tm->tm_mday = bcd2bin(regs[ISL1208_REG_DTA - ISL1208_REG_SCA] & 0x3f);
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700375 tm->tm_mon =
Adrian Bunkfe20ba72008-10-18 20:28:41 -0700376 bcd2bin(regs[ISL1208_REG_MOA - ISL1208_REG_SCA] & 0x1f) - 1;
377 tm->tm_wday = bcd2bin(regs[ISL1208_REG_DWA - ISL1208_REG_SCA] & 0x03);
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700378
Ryan Malloncf044f02011-03-22 16:34:53 -0700379 /* The alarm doesn't store the year so get it from the rtc section */
380 yr = i2c_smbus_read_byte_data(client, ISL1208_REG_YR);
381 if (yr < 0) {
382 dev_err(&client->dev, "%s: reading RTC YR failed\n", __func__);
383 return yr;
384 }
385 tm->tm_year = bcd2bin(yr) + 100;
386
387 icr = i2c_smbus_read_byte_data(client, ISL1208_REG_INT);
388 if (icr < 0) {
389 dev_err(&client->dev, "%s: reading INT failed\n", __func__);
390 return icr;
391 }
392 alarm->enabled = !!(icr & ISL1208_REG_INT_ALME);
393
394 return 0;
395}
396
397static int
398isl1208_i2c_set_alarm(struct i2c_client *client, struct rtc_wkalrm *alarm)
399{
400 struct rtc_time *alarm_tm = &alarm->time;
401 u8 regs[ISL1208_ALARM_SECTION_LEN] = { 0, };
402 const int offs = ISL1208_REG_SCA;
Ryan Malloncf044f02011-03-22 16:34:53 -0700403 struct rtc_time rtc_tm;
404 int err, enable;
405
406 err = isl1208_i2c_read_time(client, &rtc_tm);
407 if (err)
408 return err;
Ryan Malloncf044f02011-03-22 16:34:53 -0700409
410 /* If the alarm time is before the current time disable the alarm */
Xunlei Pangf118db12015-06-12 10:04:11 +0800411 if (!alarm->enabled || rtc_tm_sub(alarm_tm, &rtc_tm) <= 0)
Ryan Malloncf044f02011-03-22 16:34:53 -0700412 enable = 0x00;
413 else
414 enable = 0x80;
415
416 /* Program the alarm and enable it for each setting */
417 regs[ISL1208_REG_SCA - offs] = bin2bcd(alarm_tm->tm_sec) | enable;
418 regs[ISL1208_REG_MNA - offs] = bin2bcd(alarm_tm->tm_min) | enable;
419 regs[ISL1208_REG_HRA - offs] = bin2bcd(alarm_tm->tm_hour) |
420 ISL1208_REG_HR_MIL | enable;
421
422 regs[ISL1208_REG_DTA - offs] = bin2bcd(alarm_tm->tm_mday) | enable;
423 regs[ISL1208_REG_MOA - offs] = bin2bcd(alarm_tm->tm_mon + 1) | enable;
424 regs[ISL1208_REG_DWA - offs] = bin2bcd(alarm_tm->tm_wday & 7) | enable;
425
426 /* write ALARM registers */
427 err = isl1208_i2c_set_regs(client, offs, regs,
428 ISL1208_ALARM_SECTION_LEN);
429 if (err < 0) {
430 dev_err(&client->dev, "%s: writing ALARM section failed\n",
431 __func__);
432 return err;
433 }
434
435 err = isl1208_rtc_toggle_alarm(client, enable);
436 if (err)
437 return err;
438
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700439 return 0;
440}
441
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700442static int
443isl1208_rtc_read_time(struct device *dev, struct rtc_time *tm)
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700444{
445 return isl1208_i2c_read_time(to_i2c_client(dev), tm);
446}
447
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700448static int
449isl1208_i2c_set_time(struct i2c_client *client, struct rtc_time const *tm)
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700450{
451 int sr;
452 u8 regs[ISL1208_RTC_SECTION_LEN] = { 0, };
453
Chris Elstoncc6c2ca2008-12-23 13:57:10 -0800454 /* The clock has an 8 bit wide bcd-coded register (they never learn)
455 * for the year. tm_year is an offset from 1900 and we are interested
456 * in the 2000-2099 range, so any value less than 100 is invalid.
457 */
458 if (tm->tm_year < 100)
459 return -EINVAL;
460
Adrian Bunkfe20ba72008-10-18 20:28:41 -0700461 regs[ISL1208_REG_SC] = bin2bcd(tm->tm_sec);
462 regs[ISL1208_REG_MN] = bin2bcd(tm->tm_min);
463 regs[ISL1208_REG_HR] = bin2bcd(tm->tm_hour) | ISL1208_REG_HR_MIL;
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700464
Adrian Bunkfe20ba72008-10-18 20:28:41 -0700465 regs[ISL1208_REG_DT] = bin2bcd(tm->tm_mday);
466 regs[ISL1208_REG_MO] = bin2bcd(tm->tm_mon + 1);
467 regs[ISL1208_REG_YR] = bin2bcd(tm->tm_year - 100);
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700468
Adrian Bunkfe20ba72008-10-18 20:28:41 -0700469 regs[ISL1208_REG_DW] = bin2bcd(tm->tm_wday & 7);
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700470
471 sr = isl1208_i2c_get_sr(client);
472 if (sr < 0) {
473 dev_err(&client->dev, "%s: reading SR failed\n", __func__);
474 return sr;
475 }
476
477 /* set WRTC */
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700478 sr = i2c_smbus_write_byte_data(client, ISL1208_REG_SR,
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700479 sr | ISL1208_REG_SR_WRTC);
480 if (sr < 0) {
481 dev_err(&client->dev, "%s: writing SR failed\n", __func__);
482 return sr;
483 }
484
485 /* write RTC registers */
486 sr = isl1208_i2c_set_regs(client, 0, regs, ISL1208_RTC_SECTION_LEN);
487 if (sr < 0) {
488 dev_err(&client->dev, "%s: writing RTC section failed\n",
489 __func__);
490 return sr;
491 }
492
493 /* clear WRTC again */
Denis Osterland5b9fc7952018-01-23 13:17:58 +0100494 sr = isl1208_i2c_get_sr(client);
495 if (sr < 0) {
496 dev_err(&client->dev, "%s: reading SR failed\n", __func__);
497 return sr;
498 }
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700499 sr = i2c_smbus_write_byte_data(client, ISL1208_REG_SR,
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700500 sr & ~ISL1208_REG_SR_WRTC);
501 if (sr < 0) {
502 dev_err(&client->dev, "%s: writing SR failed\n", __func__);
503 return sr;
504 }
505
506 return 0;
507}
508
509
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700510static int
511isl1208_rtc_set_time(struct device *dev, struct rtc_time *tm)
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700512{
513 return isl1208_i2c_set_time(to_i2c_client(dev), tm);
514}
515
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700516static int
517isl1208_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700518{
519 return isl1208_i2c_read_alarm(to_i2c_client(dev), alarm);
520}
521
Ryan Malloncf044f02011-03-22 16:34:53 -0700522static int
523isl1208_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
524{
525 return isl1208_i2c_set_alarm(to_i2c_client(dev), alarm);
526}
527
Michael Grzeschikdd35bdb2018-07-24 11:31:21 +0000528static ssize_t timestamp0_store(struct device *dev,
529 struct device_attribute *attr,
530 const char *buf, size_t count)
531{
Alexandre Belloni1b4c7942018-09-15 13:29:56 +0200532 struct i2c_client *client = to_i2c_client(dev->parent);
Michael Grzeschikdd35bdb2018-07-24 11:31:21 +0000533 int sr;
534
535 sr = isl1208_i2c_get_sr(client);
536 if (sr < 0) {
537 dev_err(dev, "%s: reading SR failed\n", __func__);
538 return sr;
539 }
540
541 sr &= ~ISL1208_REG_SR_EVT;
542
543 sr = i2c_smbus_write_byte_data(client, ISL1208_REG_SR, sr);
544 if (sr < 0)
545 dev_err(dev, "%s: writing SR failed\n",
546 __func__);
547
548 return count;
549};
550
551static ssize_t timestamp0_show(struct device *dev,
552 struct device_attribute *attr, char *buf)
553{
Alexandre Belloni1b4c7942018-09-15 13:29:56 +0200554 struct i2c_client *client = to_i2c_client(dev->parent);
Michael Grzeschikdd35bdb2018-07-24 11:31:21 +0000555 u8 regs[ISL1219_EVT_SECTION_LEN] = { 0, };
556 struct rtc_time tm;
557 int sr;
558
559 sr = isl1208_i2c_get_sr(client);
560 if (sr < 0) {
561 dev_err(dev, "%s: reading SR failed\n", __func__);
562 return sr;
563 }
564
565 if (!(sr & ISL1208_REG_SR_EVT))
566 return 0;
567
568 sr = isl1208_i2c_read_regs(client, ISL1219_REG_SCT, regs,
569 ISL1219_EVT_SECTION_LEN);
570 if (sr < 0) {
571 dev_err(dev, "%s: reading event section failed\n",
572 __func__);
573 return 0;
574 }
575
576 /* MSB of each alarm register is an enable bit */
577 tm.tm_sec = bcd2bin(regs[ISL1219_REG_SCT - ISL1219_REG_SCT] & 0x7f);
578 tm.tm_min = bcd2bin(regs[ISL1219_REG_MNT - ISL1219_REG_SCT] & 0x7f);
579 tm.tm_hour = bcd2bin(regs[ISL1219_REG_HRT - ISL1219_REG_SCT] & 0x3f);
580 tm.tm_mday = bcd2bin(regs[ISL1219_REG_DTT - ISL1219_REG_SCT] & 0x3f);
581 tm.tm_mon =
582 bcd2bin(regs[ISL1219_REG_MOT - ISL1219_REG_SCT] & 0x1f) - 1;
583 tm.tm_year = bcd2bin(regs[ISL1219_REG_YRT - ISL1219_REG_SCT]) + 100;
584
585 sr = rtc_valid_tm(&tm);
586 if (sr)
587 return sr;
588
589 return sprintf(buf, "%llu\n",
590 (unsigned long long)rtc_tm_to_time64(&tm));
591};
592
593static DEVICE_ATTR_RW(timestamp0);
594
Ryan Malloncf044f02011-03-22 16:34:53 -0700595static irqreturn_t
596isl1208_rtc_interrupt(int irq, void *data)
597{
598 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
599 struct i2c_client *client = data;
Trent Piephoed3c52a2019-02-12 02:34:03 +0000600 struct isl1208_state *isl1208 = i2c_get_clientdata(client);
Ryan Malloncf044f02011-03-22 16:34:53 -0700601 int handled = 0, sr, err;
602
603 /*
604 * I2C reads get NAK'ed if we read straight away after an interrupt?
605 * Using a mdelay/msleep didn't seem to help either, so we work around
606 * this by continually trying to read the register for a short time.
607 */
608 while (1) {
609 sr = isl1208_i2c_get_sr(client);
610 if (sr >= 0)
611 break;
612
613 if (time_after(jiffies, timeout)) {
614 dev_err(&client->dev, "%s: reading SR failed\n",
615 __func__);
616 return sr;
617 }
618 }
619
620 if (sr & ISL1208_REG_SR_ALM) {
621 dev_dbg(&client->dev, "alarm!\n");
622
Trent Piephoed3c52a2019-02-12 02:34:03 +0000623 rtc_update_irq(isl1208->rtc, 1, RTC_IRQF | RTC_AF);
Jan Luebbe72fca4a2013-02-04 14:28:53 -0800624
Ryan Malloncf044f02011-03-22 16:34:53 -0700625 /* Clear the alarm */
626 sr &= ~ISL1208_REG_SR_ALM;
627 sr = i2c_smbus_write_byte_data(client, ISL1208_REG_SR, sr);
628 if (sr < 0)
629 dev_err(&client->dev, "%s: writing SR failed\n",
630 __func__);
631 else
632 handled = 1;
633
634 /* Disable the alarm */
635 err = isl1208_rtc_toggle_alarm(client, 0);
636 if (err)
637 return err;
638 }
639
Trent Piepho5909b872019-02-12 02:34:04 +0000640 if (isl1208->config->has_tamper && (sr & ISL1208_REG_SR_EVT)) {
Michael Grzeschikdd35bdb2018-07-24 11:31:21 +0000641 dev_warn(&client->dev, "event detected");
642 handled = 1;
Trent Piepho5909b872019-02-12 02:34:04 +0000643 if (isl1208->config->has_timestamp)
644 sysfs_notify(&isl1208->rtc->dev.kobj, NULL,
645 dev_attr_timestamp0.attr.name);
Michael Grzeschikdd35bdb2018-07-24 11:31:21 +0000646 }
647
Ryan Malloncf044f02011-03-22 16:34:53 -0700648 return handled ? IRQ_HANDLED : IRQ_NONE;
649}
650
David Brownellff8371a2006-09-30 23:28:17 -0700651static const struct rtc_class_ops isl1208_rtc_ops = {
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700652 .proc = isl1208_rtc_proc,
653 .read_time = isl1208_rtc_read_time,
654 .set_time = isl1208_rtc_set_time,
655 .read_alarm = isl1208_rtc_read_alarm,
Ryan Malloncf044f02011-03-22 16:34:53 -0700656 .set_alarm = isl1208_rtc_set_alarm,
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700657};
658
659/* sysfs interface */
660
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700661static ssize_t
662isl1208_sysfs_show_atrim(struct device *dev,
663 struct device_attribute *attr, char *buf)
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700664{
Alexandre Belloni1b4c7942018-09-15 13:29:56 +0200665 int atr = isl1208_i2c_get_atr(to_i2c_client(dev->parent));
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700666 if (atr < 0)
667 return atr;
668
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700669 return sprintf(buf, "%d.%.2d pF\n", atr >> 2, (atr & 0x3) * 25);
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700670}
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700671
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700672static DEVICE_ATTR(atrim, S_IRUGO, isl1208_sysfs_show_atrim, NULL);
673
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700674static ssize_t
675isl1208_sysfs_show_dtrim(struct device *dev,
676 struct device_attribute *attr, char *buf)
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700677{
Alexandre Belloni1b4c7942018-09-15 13:29:56 +0200678 int dtr = isl1208_i2c_get_dtr(to_i2c_client(dev->parent));
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700679 if (dtr < 0)
680 return dtr;
681
Trent Piephoc8c97a4f2019-01-02 16:00:17 +0000682 return sprintf(buf, "%d ppm\n", dtr - 100);
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700683}
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700684
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700685static DEVICE_ATTR(dtrim, S_IRUGO, isl1208_sysfs_show_dtrim, NULL);
686
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700687static ssize_t
688isl1208_sysfs_show_usr(struct device *dev,
689 struct device_attribute *attr, char *buf)
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700690{
Alexandre Belloni1b4c7942018-09-15 13:29:56 +0200691 int usr = isl1208_i2c_get_usr(to_i2c_client(dev->parent));
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700692 if (usr < 0)
693 return usr;
694
695 return sprintf(buf, "0x%.4x\n", usr);
696}
697
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700698static ssize_t
699isl1208_sysfs_store_usr(struct device *dev,
700 struct device_attribute *attr,
701 const char *buf, size_t count)
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700702{
703 int usr = -1;
704
705 if (buf[0] == '0' && (buf[1] == 'x' || buf[1] == 'X')) {
706 if (sscanf(buf, "%x", &usr) != 1)
707 return -EINVAL;
708 } else {
709 if (sscanf(buf, "%d", &usr) != 1)
710 return -EINVAL;
711 }
712
713 if (usr < 0 || usr > 0xffff)
714 return -EINVAL;
715
Alexandre Belloni1b4c7942018-09-15 13:29:56 +0200716 if (isl1208_i2c_set_usr(to_i2c_client(dev->parent), usr))
717 return -EIO;
718
719 return count;
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700720}
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700721
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700722static DEVICE_ATTR(usr, S_IRUGO | S_IWUSR, isl1208_sysfs_show_usr,
723 isl1208_sysfs_store_usr);
724
H Hartley Sweetene17ab5cb2010-05-24 14:33:46 -0700725static struct attribute *isl1208_rtc_attrs[] = {
726 &dev_attr_atrim.attr,
727 &dev_attr_dtrim.attr,
728 &dev_attr_usr.attr,
729 NULL
730};
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700731
H Hartley Sweetene17ab5cb2010-05-24 14:33:46 -0700732static const struct attribute_group isl1208_rtc_sysfs_files = {
733 .attrs = isl1208_rtc_attrs,
734};
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700735
Michael Grzeschikdd35bdb2018-07-24 11:31:21 +0000736static struct attribute *isl1219_rtc_attrs[] = {
737 &dev_attr_timestamp0.attr,
738 NULL
739};
740
741static const struct attribute_group isl1219_rtc_sysfs_files = {
742 .attrs = isl1219_rtc_attrs,
743};
744
Denis Osterland9ece7cd2018-07-24 11:31:21 +0000745static int isl1208_setup_irq(struct i2c_client *client, int irq)
746{
747 int rc = devm_request_threaded_irq(&client->dev, irq, NULL,
748 isl1208_rtc_interrupt,
749 IRQF_SHARED | IRQF_ONESHOT,
750 isl1208_driver.driver.name,
751 client);
752 if (!rc) {
753 device_init_wakeup(&client->dev, 1);
754 enable_irq_wake(irq);
755 } else {
756 dev_err(&client->dev,
757 "Unable to request irq %d, no alarm support\n",
758 irq);
759 }
760 return rc;
761}
762
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700763static int
Jean Delvared2653e92008-04-29 23:11:39 +0200764isl1208_probe(struct i2c_client *client, const struct i2c_device_id *id)
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700765{
766 int rc = 0;
Trent Piephoed3c52a2019-02-12 02:34:03 +0000767 struct isl1208_state *isl1208;
Denis Osterland9ece7cd2018-07-24 11:31:21 +0000768 int evdet_irq = -1;
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700769
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700770 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
771 return -ENODEV;
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700772
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700773 if (isl1208_i2c_validate_client(client) < 0)
774 return -ENODEV;
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700775
Trent Piephoed3c52a2019-02-12 02:34:03 +0000776 /* Allocate driver state, point i2c client data to it */
777 isl1208 = devm_kzalloc(&client->dev, sizeof(*isl1208), GFP_KERNEL);
778 if (!isl1208)
779 return -ENOMEM;
780 i2c_set_clientdata(client, isl1208);
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700781
Trent Piepho5909b872019-02-12 02:34:04 +0000782 /* Determine which chip we have */
783 if (client->dev.of_node) {
784 isl1208->config = of_device_get_match_data(&client->dev);
785 if (!isl1208->config)
786 return -ENODEV;
787 } else {
788 if (id->driver_data >= ISL_LAST_ID)
789 return -ENODEV;
790 isl1208->config = &isl1208_configs[id->driver_data];
791 }
792
Trent Piephoed3c52a2019-02-12 02:34:03 +0000793 isl1208->rtc = devm_rtc_allocate_device(&client->dev);
794 if (IS_ERR(isl1208->rtc))
795 return PTR_ERR(isl1208->rtc);
Denis Osterland236b7182018-03-05 10:43:53 +0000796
Trent Piephoed3c52a2019-02-12 02:34:03 +0000797 isl1208->rtc->ops = &isl1208_rtc_ops;
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700798
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700799 rc = isl1208_i2c_get_sr(client);
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700800 if (rc < 0) {
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700801 dev_err(&client->dev, "reading status failed\n");
Sachin Kamatadce8c12013-11-12 15:10:30 -0800802 return rc;
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700803 }
804
805 if (rc & ISL1208_REG_SR_RTCF)
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700806 dev_warn(&client->dev, "rtc power failure detected, "
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700807 "please set clock.\n");
808
Trent Piepho5909b872019-02-12 02:34:04 +0000809 if (isl1208->config->has_tamper) {
Denis Osterlandcfa30622018-07-24 11:31:21 +0000810 struct device_node *np = client->dev.of_node;
811 u32 evienb;
812
813 rc = i2c_smbus_read_byte_data(client, ISL1219_REG_EV);
814 if (rc < 0) {
815 dev_err(&client->dev, "failed to read EV reg\n");
816 return rc;
817 }
818 rc |= ISL1219_REG_EV_EVEN;
819 if (!of_property_read_u32(np, "isil,ev-evienb", &evienb)) {
820 if (evienb)
821 rc |= ISL1219_REG_EV_EVIENB;
822 else
823 rc &= ~ISL1219_REG_EV_EVIENB;
824 }
825 rc = i2c_smbus_write_byte_data(client, ISL1219_REG_EV, rc);
Michael Grzeschikdd35bdb2018-07-24 11:31:21 +0000826 if (rc < 0) {
827 dev_err(&client->dev, "could not enable tamper detection\n");
828 return rc;
829 }
Trent Piepho5909b872019-02-12 02:34:04 +0000830 evdet_irq = of_irq_get_byname(np, "evdet");
831 }
832 if (isl1208->config->has_timestamp) {
Trent Piephoed3c52a2019-02-12 02:34:03 +0000833 rc = rtc_add_group(isl1208->rtc, &isl1219_rtc_sysfs_files);
Michael Grzeschikdd35bdb2018-07-24 11:31:21 +0000834 if (rc)
835 return rc;
836 }
837
Trent Piephoed3c52a2019-02-12 02:34:03 +0000838 rc = rtc_add_group(isl1208->rtc, &isl1208_rtc_sysfs_files);
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700839 if (rc)
Sachin Kamatadce8c12013-11-12 15:10:30 -0800840 return rc;
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700841
Denis Osterland9ece7cd2018-07-24 11:31:21 +0000842 if (client->irq > 0)
843 rc = isl1208_setup_irq(client, client->irq);
844 if (rc)
845 return rc;
846
847 if (evdet_irq > 0 && evdet_irq != client->irq)
848 rc = isl1208_setup_irq(client, evdet_irq);
849 if (rc)
850 return rc;
Michael Grzeschik9d327c22018-03-05 10:43:53 +0000851
Trent Piephoed3c52a2019-02-12 02:34:03 +0000852 return rtc_register_device(isl1208->rtc);
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700853}
854
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700855static struct i2c_driver isl1208_driver = {
856 .driver = {
Javier Martinez Canillas03835502017-03-03 11:29:20 -0300857 .name = "rtc-isl1208",
858 .of_match_table = of_match_ptr(isl1208_of_match),
859 },
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700860 .probe = isl1208_probe,
Jean Delvare3760f732008-04-29 23:11:40 +0200861 .id_table = isl1208_id,
Alessandro Zummo9edae7b2008-04-28 02:11:53 -0700862};
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700863
Axel Lin0abc9202012-03-23 15:02:31 -0700864module_i2c_driver(isl1208_driver);
Herbert Valerio Riedel7e56a7d2006-07-14 00:24:11 -0700865
866MODULE_AUTHOR("Herbert Valerio Riedel <hvr@gnu.org>");
867MODULE_DESCRIPTION("Intersil ISL1208 RTC driver");
868MODULE_LICENSE("GPL");