1 // SPDX-License-Identifier: GPL-2.0
3 * RTC driver for the MAX31335
5 * Copyright (C) 2023 Analog Devices
7 * Antoniu Miclaus <antoniu.miclaus@analog.com>
11 #include <linux/unaligned.h>
12 #include <linux/bcd.h>
13 #include <linux/bitfield.h>
14 #include <linux/bitops.h>
15 #include <linux/clk.h>
16 #include <linux/clk-provider.h>
17 #include <linux/hwmon.h>
18 #include <linux/i2c.h>
19 #include <linux/interrupt.h>
20 #include <linux/kernel.h>
21 #include <linux/module.h>
22 #include <linux/of_device.h>
23 #include <linux/regmap.h>
24 #include <linux/rtc.h>
25 #include <linux/util_macros.h>
27 /* MAX31335 Register Map */
28 #define MAX31335_STATUS1 0x00
29 #define MAX31335_INT_EN1 0x01
30 #define MAX31335_STATUS2 0x02
31 #define MAX31335_INT_EN2 0x03
32 #define MAX31335_RTC_RESET 0x04
33 #define MAX31335_RTC_CONFIG 0x05
34 #define MAX31335_RTC_CONFIG2 0x06
35 #define MAX31335_TIMESTAMP_CONFIG 0x07
36 #define MAX31335_TIMER_CONFIG 0x08
37 #define MAX31335_SECONDS_1_128 0x09
38 #define MAX31335_SECONDS 0x0A
39 #define MAX31335_MINUTES 0x0B
40 #define MAX31335_HOURS 0x0C
41 #define MAX31335_DAY 0x0D
42 #define MAX31335_DATE 0x0E
43 #define MAX31335_MONTH 0x0F
44 #define MAX31335_YEAR 0x0F
45 #define MAX31335_ALM1_SEC 0x11
46 #define MAX31335_ALM1_MIN 0x12
47 #define MAX31335_ALM1_HRS 0x13
48 #define MAX31335_ALM1_DAY_DATE 0x14
49 #define MAX31335_ALM1_MON 0x15
50 #define MAX31335_ALM1_YEAR 0x16
51 #define MAX31335_ALM2_MIN 0x17
52 #define MAX31335_ALM2_HRS 0x18
53 #define MAX31335_ALM2_DAY_DATE 0x19
54 #define MAX31335_TIMER_COUNT 0x1A
55 #define MAX31335_TIMER_INIT 0x1B
56 #define MAX31335_PWR_MGMT 0x1C
57 #define MAX31335_TRICKLE_REG 0x1D
58 #define MAX31335_AGING_OFFSET 0x1E
59 #define MAX31335_TS_CONFIG 0x30
60 #define MAX31335_TEMP_ALARM_HIGH_MSB 0x31
61 #define MAX31335_TEMP_ALARM_HIGH_LSB 0x32
62 #define MAX31335_TEMP_ALARM_LOW_MSB 0x33
63 #define MAX31335_TEMP_ALARM_LOW_LSB 0x34
64 #define MAX31335_TEMP_DATA_MSB 0x35
65 #define MAX31335_TEMP_DATA_LSB 0x36
66 #define MAX31335_TS0_SEC_1_128 0x40
67 #define MAX31335_TS0_SEC 0x41
68 #define MAX31335_TS0_MIN 0x42
69 #define MAX31335_TS0_HOUR 0x43
70 #define MAX31335_TS0_DATE 0x44
71 #define MAX31335_TS0_MONTH 0x45
72 #define MAX31335_TS0_YEAR 0x46
73 #define MAX31335_TS0_FLAGS 0x47
74 #define MAX31335_TS1_SEC_1_128 0x48
75 #define MAX31335_TS1_SEC 0x49
76 #define MAX31335_TS1_MIN 0x4A
77 #define MAX31335_TS1_HOUR 0x4B
78 #define MAX31335_TS1_DATE 0x4C
79 #define MAX31335_TS1_MONTH 0x4D
80 #define MAX31335_TS1_YEAR 0x4E
81 #define MAX31335_TS1_FLAGS 0x4F
82 #define MAX31335_TS2_SEC_1_128 0x50
83 #define MAX31335_TS2_SEC 0x51
84 #define MAX31335_TS2_MIN 0x52
85 #define MAX31335_TS2_HOUR 0x53
86 #define MAX31335_TS2_DATE 0x54
87 #define MAX31335_TS2_MONTH 0x55
88 #define MAX31335_TS2_YEAR 0x56
89 #define MAX31335_TS2_FLAGS 0x57
90 #define MAX31335_TS3_SEC_1_128 0x58
91 #define MAX31335_TS3_SEC 0x59
92 #define MAX31335_TS3_MIN 0x5A
93 #define MAX31335_TS3_HOUR 0x5B
94 #define MAX31335_TS3_DATE 0x5C
95 #define MAX31335_TS3_MONTH 0x5D
96 #define MAX31335_TS3_YEAR 0x5E
97 #define MAX31335_TS3_FLAGS 0x5F
99 /* MAX31335_STATUS1 Bit Definitions */
100 #define MAX31335_STATUS1_PSDECT BIT(7)
101 #define MAX31335_STATUS1_OSF BIT(6)
102 #define MAX31335_STATUS1_PFAIL BIT(5)
103 #define MAX31335_STATUS1_VBATLOW BIT(4)
104 #define MAX31335_STATUS1_DIF BIT(3)
105 #define MAX31335_STATUS1_TIF BIT(2)
106 #define MAX31335_STATUS1_A2F BIT(1)
107 #define MAX31335_STATUS1_A1F BIT(0)
109 /* MAX31335_INT_EN1 Bit Definitions */
110 #define MAX31335_INT_EN1_DOSF BIT(6)
111 #define MAX31335_INT_EN1_PFAILE BIT(5)
112 #define MAX31335_INT_EN1_VBATLOWE BIT(4)
113 #define MAX31335_INT_EN1_DIE BIT(3)
114 #define MAX31335_INT_EN1_TIE BIT(2)
115 #define MAX31335_INT_EN1_A2IE BIT(1)
116 #define MAX31335_INT_EN1_A1IE BIT(0)
118 /* MAX31335_STATUS2 Bit Definitions */
119 #define MAX31335_STATUS2_TEMP_RDY BIT(2)
120 #define MAX31335_STATUS2_OTF BIT(1)
121 #define MAX31335_STATUS2_UTF BIT(0)
123 /* MAX31335_INT_EN2 Bit Definitions */
124 #define MAX31335_INT_EN2_TEMP_RDY_EN BIT(2)
125 #define MAX31335_INT_EN2_OTIE BIT(1)
126 #define MAX31335_INT_EN2_UTIE BIT(0)
128 /* MAX31335_RTC_RESET Bit Definitions */
129 #define MAX31335_RTC_RESET_SWRST BIT(0)
131 /* MAX31335_RTC_CONFIG1 Bit Definitions */
132 #define MAX31335_RTC_CONFIG1_EN_IO BIT(6)
133 #define MAX31335_RTC_CONFIG1_A1AC GENMASK(5, 4)
134 #define MAX31335_RTC_CONFIG1_DIP BIT(3)
135 #define MAX31335_RTC_CONFIG1_I2C_TIMEOUT BIT(1)
136 #define MAX31335_RTC_CONFIG1_EN_OSC BIT(0)
138 /* MAX31335_RTC_CONFIG2 Bit Definitions */
139 #define MAX31335_RTC_CONFIG2_ENCLKO BIT(2)
140 #define MAX31335_RTC_CONFIG2_CLKO_HZ GENMASK(1, 0)
142 /* MAX31335_TIMESTAMP_CONFIG Bit Definitions */
143 #define MAX31335_TIMESTAMP_CONFIG_TSVLOW BIT(5)
144 #define MAX31335_TIMESTAMP_CONFIG_TSPWM BIT(4)
145 #define MAX31335_TIMESTAMP_CONFIG_TSDIN BIT(3)
146 #define MAX31335_TIMESTAMP_CONFIG_TSOW BIT(2)
147 #define MAX31335_TIMESTAMP_CONFIG_TSR BIT(1)
148 #define MAX31335_TIMESTAMP_CONFIG_TSE BIT(0)
150 /* MAX31335_TIMER_CONFIG Bit Definitions */
151 #define MAX31335_TIMER_CONFIG_TE BIT(4)
152 #define MAX31335_TIMER_CONFIG_TPAUSE BIT(3)
153 #define MAX31335_TIMER_CONFIG_TRPT BIT(2)
154 #define MAX31335_TIMER_CONFIG_TFS GENMASK(1, 0)
156 /* MAX31335_HOURS Bit Definitions */
157 #define MAX31335_HOURS_F_24_12 BIT(6)
158 #define MAX31335_HOURS_HR_20_AM_PM BIT(5)
160 /* MAX31335_MONTH Bit Definitions */
161 #define MAX31335_MONTH_CENTURY BIT(7)
163 /* MAX31335_PWR_MGMT Bit Definitions */
164 #define MAX31335_PWR_MGMT_PFVT BIT(0)
166 /* MAX31335_TRICKLE_REG Bit Definitions */
167 #define MAX31335_TRICKLE_REG_TRICKLE GENMASK(3, 1)
168 #define MAX31335_TRICKLE_REG_EN_TRICKLE BIT(0)
170 /* MAX31335_TS_CONFIG Bit Definitions */
171 #define MAX31335_TS_CONFIG_AUTO BIT(4)
172 #define MAX31335_TS_CONFIG_CONVERT_T BIT(3)
173 #define MAX31335_TS_CONFIG_TSINT GENMASK(2, 0)
175 /* MAX31335_TS_FLAGS Bit Definitions */
176 #define MAX31335_TS_FLAGS_VLOWF BIT(3)
177 #define MAX31335_TS_FLAGS_VBATF BIT(2)
178 #define MAX31335_TS_FLAGS_VCCF BIT(1)
179 #define MAX31335_TS_FLAGS_DINF BIT(0)
181 /* MAX31335 Miscellaneous Definitions */
182 #define MAX31335_TRICKLE_SCHOTTKY_DIODE 1
183 #define MAX31335_TRICKLE_STANDARD_DIODE 4
184 #define MAX31335_RAM_SIZE 32
185 #define MAX31335_TIME_SIZE 0x07
187 #define clk_hw_to_max31335(_hw) container_of(_hw, struct max31335_data, clkout)
189 struct max31335_data
{
190 struct regmap
*regmap
;
191 struct rtc_device
*rtc
;
192 struct clk_hw clkout
;
195 static const int max31335_clkout_freq
[] = { 1, 64, 1024, 32768 };
197 static const u16 max31335_trickle_resistors
[] = {3000, 6000, 11000};
199 static bool max31335_volatile_reg(struct device
*dev
, unsigned int reg
)
201 /* time keeping registers */
202 if (reg
>= MAX31335_SECONDS
&&
203 reg
< MAX31335_SECONDS
+ MAX31335_TIME_SIZE
)
206 /* interrupt status register */
207 if (reg
== MAX31335_STATUS1
)
210 /* temperature registers */
211 if (reg
== MAX31335_TEMP_DATA_MSB
|| reg
== MAX31335_TEMP_DATA_LSB
)
217 static const struct regmap_config regmap_config
= {
220 .max_register
= 0x5F,
221 .volatile_reg
= max31335_volatile_reg
,
224 static int max31335_read_time(struct device
*dev
, struct rtc_time
*tm
)
226 struct max31335_data
*max31335
= dev_get_drvdata(dev
);
230 ret
= regmap_bulk_read(max31335
->regmap
, MAX31335_SECONDS
, date
,
235 tm
->tm_sec
= bcd2bin(date
[0] & 0x7f);
236 tm
->tm_min
= bcd2bin(date
[1] & 0x7f);
237 tm
->tm_hour
= bcd2bin(date
[2] & 0x3f);
238 tm
->tm_wday
= bcd2bin(date
[3] & 0x7) - 1;
239 tm
->tm_mday
= bcd2bin(date
[4] & 0x3f);
240 tm
->tm_mon
= bcd2bin(date
[5] & 0x1f) - 1;
241 tm
->tm_year
= bcd2bin(date
[6]) + 100;
243 if (FIELD_GET(MAX31335_MONTH_CENTURY
, date
[5]))
249 static int max31335_set_time(struct device
*dev
, struct rtc_time
*tm
)
251 struct max31335_data
*max31335
= dev_get_drvdata(dev
);
254 date
[0] = bin2bcd(tm
->tm_sec
);
255 date
[1] = bin2bcd(tm
->tm_min
);
256 date
[2] = bin2bcd(tm
->tm_hour
);
257 date
[3] = bin2bcd(tm
->tm_wday
+ 1);
258 date
[4] = bin2bcd(tm
->tm_mday
);
259 date
[5] = bin2bcd(tm
->tm_mon
+ 1);
260 date
[6] = bin2bcd(tm
->tm_year
% 100);
262 if (tm
->tm_year
>= 200)
263 date
[5] |= FIELD_PREP(MAX31335_MONTH_CENTURY
, 1);
265 return regmap_bulk_write(max31335
->regmap
, MAX31335_SECONDS
, date
,
269 static int max31335_read_alarm(struct device
*dev
, struct rtc_wkalrm
*alrm
)
271 struct max31335_data
*max31335
= dev_get_drvdata(dev
);
272 int ret
, ctrl
, status
;
273 struct rtc_time time
;
276 ret
= regmap_bulk_read(max31335
->regmap
, MAX31335_ALM1_SEC
, regs
,
281 alrm
->time
.tm_sec
= bcd2bin(regs
[0] & 0x7f);
282 alrm
->time
.tm_min
= bcd2bin(regs
[1] & 0x7f);
283 alrm
->time
.tm_hour
= bcd2bin(regs
[2] & 0x3f);
284 alrm
->time
.tm_mday
= bcd2bin(regs
[3] & 0x3f);
285 alrm
->time
.tm_mon
= bcd2bin(regs
[4] & 0x1f) - 1;
286 alrm
->time
.tm_year
= bcd2bin(regs
[5]) + 100;
288 ret
= max31335_read_time(dev
, &time
);
292 if (time
.tm_year
>= 200)
293 alrm
->time
.tm_year
+= 100;
295 ret
= regmap_read(max31335
->regmap
, MAX31335_INT_EN1
, &ctrl
);
299 ret
= regmap_read(max31335
->regmap
, MAX31335_STATUS1
, &status
);
303 alrm
->enabled
= FIELD_GET(MAX31335_INT_EN1_A1IE
, ctrl
);
304 alrm
->pending
= FIELD_GET(MAX31335_STATUS1_A1F
, status
);
309 static int max31335_set_alarm(struct device
*dev
, struct rtc_wkalrm
*alrm
)
311 struct max31335_data
*max31335
= dev_get_drvdata(dev
);
316 regs
[0] = bin2bcd(alrm
->time
.tm_sec
);
317 regs
[1] = bin2bcd(alrm
->time
.tm_min
);
318 regs
[2] = bin2bcd(alrm
->time
.tm_hour
);
319 regs
[3] = bin2bcd(alrm
->time
.tm_mday
);
320 regs
[4] = bin2bcd(alrm
->time
.tm_mon
+ 1);
321 regs
[5] = bin2bcd(alrm
->time
.tm_year
% 100);
323 ret
= regmap_bulk_write(max31335
->regmap
, MAX31335_ALM1_SEC
,
328 reg
= FIELD_PREP(MAX31335_INT_EN1_A1IE
, alrm
->enabled
);
329 ret
= regmap_update_bits(max31335
->regmap
, MAX31335_INT_EN1
,
330 MAX31335_INT_EN1_A1IE
, reg
);
334 ret
= regmap_update_bits(max31335
->regmap
, MAX31335_STATUS1
,
335 MAX31335_STATUS1_A1F
, 0);
340 static int max31335_alarm_irq_enable(struct device
*dev
, unsigned int enabled
)
342 struct max31335_data
*max31335
= dev_get_drvdata(dev
);
344 return regmap_update_bits(max31335
->regmap
, MAX31335_INT_EN1
,
345 MAX31335_INT_EN1_A1IE
, enabled
);
348 static irqreturn_t
max31335_handle_irq(int irq
, void *dev_id
)
350 struct max31335_data
*max31335
= dev_id
;
354 ret
= regmap_update_bits_check(max31335
->regmap
, MAX31335_STATUS1
,
355 MAX31335_STATUS1_A1F
, 0, &status
);
360 rtc_update_irq(max31335
->rtc
, 1, RTC_AF
| RTC_IRQF
);
365 static const struct rtc_class_ops max31335_rtc_ops
= {
366 .read_time
= max31335_read_time
,
367 .set_time
= max31335_set_time
,
368 .read_alarm
= max31335_read_alarm
,
369 .set_alarm
= max31335_set_alarm
,
370 .alarm_irq_enable
= max31335_alarm_irq_enable
,
373 static int max31335_trickle_charger_setup(struct device
*dev
,
374 struct max31335_data
*max31335
)
376 u32 ohms
, chargeable
;
380 if (device_property_read_u32(dev
, "aux-voltage-chargeable",
384 if (device_property_read_u32(dev
, "trickle-resistor-ohms", &ohms
))
387 if (device_property_read_string(dev
, "adi,tc-diode", &diode
))
390 if (!strcmp(diode
, "schottky"))
391 trickle_cfg
= MAX31335_TRICKLE_SCHOTTKY_DIODE
;
392 else if (!strcmp(diode
, "standard+schottky"))
393 trickle_cfg
= MAX31335_TRICKLE_STANDARD_DIODE
;
395 return dev_err_probe(dev
, -EINVAL
,
396 "Invalid tc-diode value: %s\n", diode
);
398 for (i
= 0; i
< ARRAY_SIZE(max31335_trickle_resistors
); i
++)
399 if (ohms
== max31335_trickle_resistors
[i
])
402 if (i
>= ARRAY_SIZE(max31335_trickle_resistors
))
407 return regmap_write(max31335
->regmap
, MAX31335_TRICKLE_REG
,
408 FIELD_PREP(MAX31335_TRICKLE_REG_TRICKLE
, i
) |
409 FIELD_PREP(MAX31335_TRICKLE_REG_EN_TRICKLE
,
413 static unsigned long max31335_clkout_recalc_rate(struct clk_hw
*hw
,
414 unsigned long parent_rate
)
416 struct max31335_data
*max31335
= clk_hw_to_max31335(hw
);
417 unsigned int freq_mask
;
421 ret
= regmap_read(max31335
->regmap
, MAX31335_RTC_CONFIG2
, ®
);
425 freq_mask
= __roundup_pow_of_two(ARRAY_SIZE(max31335_clkout_freq
)) - 1;
427 return max31335_clkout_freq
[reg
& freq_mask
];
430 static long max31335_clkout_round_rate(struct clk_hw
*hw
, unsigned long rate
,
431 unsigned long *prate
)
435 index
= find_closest(rate
, max31335_clkout_freq
,
436 ARRAY_SIZE(max31335_clkout_freq
));
438 return max31335_clkout_freq
[index
];
441 static int max31335_clkout_set_rate(struct clk_hw
*hw
, unsigned long rate
,
442 unsigned long parent_rate
)
444 struct max31335_data
*max31335
= clk_hw_to_max31335(hw
);
445 unsigned int freq_mask
;
448 index
= find_closest(rate
, max31335_clkout_freq
,
449 ARRAY_SIZE(max31335_clkout_freq
));
450 freq_mask
= __roundup_pow_of_two(ARRAY_SIZE(max31335_clkout_freq
)) - 1;
452 return regmap_update_bits(max31335
->regmap
, MAX31335_RTC_CONFIG2
,
456 static int max31335_clkout_enable(struct clk_hw
*hw
)
458 struct max31335_data
*max31335
= clk_hw_to_max31335(hw
);
460 return regmap_set_bits(max31335
->regmap
, MAX31335_RTC_CONFIG2
,
461 MAX31335_RTC_CONFIG2_ENCLKO
);
464 static void max31335_clkout_disable(struct clk_hw
*hw
)
466 struct max31335_data
*max31335
= clk_hw_to_max31335(hw
);
468 regmap_clear_bits(max31335
->regmap
, MAX31335_RTC_CONFIG2
,
469 MAX31335_RTC_CONFIG2_ENCLKO
);
472 static int max31335_clkout_is_enabled(struct clk_hw
*hw
)
474 struct max31335_data
*max31335
= clk_hw_to_max31335(hw
);
478 ret
= regmap_read(max31335
->regmap
, MAX31335_RTC_CONFIG2
, ®
);
482 return !!(reg
& MAX31335_RTC_CONFIG2_ENCLKO
);
485 static const struct clk_ops max31335_clkout_ops
= {
486 .recalc_rate
= max31335_clkout_recalc_rate
,
487 .round_rate
= max31335_clkout_round_rate
,
488 .set_rate
= max31335_clkout_set_rate
,
489 .enable
= max31335_clkout_enable
,
490 .disable
= max31335_clkout_disable
,
491 .is_enabled
= max31335_clkout_is_enabled
,
494 static struct clk_init_data max31335_clk_init
= {
495 .name
= "max31335-clkout",
496 .ops
= &max31335_clkout_ops
,
499 static int max31335_nvmem_reg_read(void *priv
, unsigned int offset
,
500 void *val
, size_t bytes
)
502 struct max31335_data
*max31335
= priv
;
503 unsigned int reg
= MAX31335_TS0_SEC_1_128
+ offset
;
505 return regmap_bulk_read(max31335
->regmap
, reg
, val
, bytes
);
508 static int max31335_nvmem_reg_write(void *priv
, unsigned int offset
,
509 void *val
, size_t bytes
)
511 struct max31335_data
*max31335
= priv
;
512 unsigned int reg
= MAX31335_TS0_SEC_1_128
+ offset
;
514 return regmap_bulk_write(max31335
->regmap
, reg
, val
, bytes
);
517 static struct nvmem_config max31335_nvmem_cfg
= {
518 .reg_read
= max31335_nvmem_reg_read
,
519 .reg_write
= max31335_nvmem_reg_write
,
521 .size
= MAX31335_RAM_SIZE
,
524 #if IS_REACHABLE(HWMON)
525 static int max31335_read_temp(struct device
*dev
, enum hwmon_sensor_types type
,
526 u32 attr
, int channel
, long *val
)
528 struct max31335_data
*max31335
= dev_get_drvdata(dev
);
533 if (type
!= hwmon_temp
|| attr
!= hwmon_temp_input
)
536 ret
= regmap_bulk_read(max31335
->regmap
, MAX31335_TEMP_DATA_MSB
,
541 temp
= get_unaligned_be16(reg
);
543 *val
= (temp
/ 64) * 250;
548 static umode_t
max31335_is_visible(const void *data
,
549 enum hwmon_sensor_types type
,
550 u32 attr
, int channel
)
552 if (type
== hwmon_temp
&& attr
== hwmon_temp_input
)
558 static const struct hwmon_channel_info
*max31335_info
[] = {
559 HWMON_CHANNEL_INFO(temp
, HWMON_T_INPUT
),
563 static const struct hwmon_ops max31335_hwmon_ops
= {
564 .is_visible
= max31335_is_visible
,
565 .read
= max31335_read_temp
,
568 static const struct hwmon_chip_info max31335_chip_info
= {
569 .ops
= &max31335_hwmon_ops
,
570 .info
= max31335_info
,
574 static int max31335_clkout_register(struct device
*dev
)
576 struct max31335_data
*max31335
= dev_get_drvdata(dev
);
579 if (!device_property_present(dev
, "#clock-cells"))
580 return regmap_clear_bits(max31335
->regmap
, MAX31335_RTC_CONFIG2
,
581 MAX31335_RTC_CONFIG2_ENCLKO
);
583 max31335
->clkout
.init
= &max31335_clk_init
;
585 ret
= devm_clk_hw_register(dev
, &max31335
->clkout
);
587 return dev_err_probe(dev
, ret
, "cannot register clock\n");
589 ret
= devm_of_clk_add_hw_provider(dev
, of_clk_hw_simple_get
,
592 return dev_err_probe(dev
, ret
, "cannot add hw provider\n");
594 max31335
->clkout
.clk
= devm_clk_get_enabled(dev
, NULL
);
595 if (IS_ERR(max31335
->clkout
.clk
))
596 return dev_err_probe(dev
, PTR_ERR(max31335
->clkout
.clk
),
597 "cannot enable clkout\n");
602 static int max31335_probe(struct i2c_client
*client
)
604 struct max31335_data
*max31335
;
605 #if IS_REACHABLE(HWMON)
606 struct device
*hwmon
;
610 max31335
= devm_kzalloc(&client
->dev
, sizeof(*max31335
), GFP_KERNEL
);
614 max31335
->regmap
= devm_regmap_init_i2c(client
, ®map_config
);
615 if (IS_ERR(max31335
->regmap
))
616 return PTR_ERR(max31335
->regmap
);
618 i2c_set_clientdata(client
, max31335
);
620 max31335
->rtc
= devm_rtc_allocate_device(&client
->dev
);
621 if (IS_ERR(max31335
->rtc
))
622 return PTR_ERR(max31335
->rtc
);
624 max31335
->rtc
->ops
= &max31335_rtc_ops
;
625 max31335
->rtc
->range_min
= RTC_TIMESTAMP_BEGIN_2000
;
626 max31335
->rtc
->range_max
= RTC_TIMESTAMP_END_2199
;
627 max31335
->rtc
->alarm_offset_max
= 24 * 60 * 60;
629 ret
= max31335_clkout_register(&client
->dev
);
633 if (client
->irq
> 0) {
634 ret
= devm_request_threaded_irq(&client
->dev
, client
->irq
,
635 NULL
, max31335_handle_irq
,
637 "max31335", max31335
);
639 dev_warn(&client
->dev
,
640 "unable to request IRQ, alarm max31335 disabled\n");
646 clear_bit(RTC_FEATURE_ALARM
, max31335
->rtc
->features
);
648 max31335_nvmem_cfg
.priv
= max31335
;
649 ret
= devm_rtc_nvmem_register(max31335
->rtc
, &max31335_nvmem_cfg
);
651 return dev_err_probe(&client
->dev
, ret
,
652 "cannot register rtc nvmem\n");
654 #if IS_REACHABLE(HWMON)
655 hwmon
= devm_hwmon_device_register_with_info(&client
->dev
, client
->name
,
660 return dev_err_probe(&client
->dev
, PTR_ERR(hwmon
),
661 "cannot register hwmon device\n");
664 ret
= max31335_trickle_charger_setup(&client
->dev
, max31335
);
668 return devm_rtc_register_device(max31335
->rtc
);
671 static const struct i2c_device_id max31335_id
[] = {
676 MODULE_DEVICE_TABLE(i2c
, max31335_id
);
678 static const struct of_device_id max31335_of_match
[] = {
679 { .compatible
= "adi,max31335" },
683 MODULE_DEVICE_TABLE(of
, max31335_of_match
);
685 static struct i2c_driver max31335_driver
= {
687 .name
= "rtc-max31335",
688 .of_match_table
= max31335_of_match
,
690 .probe
= max31335_probe
,
691 .id_table
= max31335_id
,
693 module_i2c_driver(max31335_driver
);
695 MODULE_AUTHOR("Antoniu Miclaus <antoniu.miclaus@analog.com>");
696 MODULE_DESCRIPTION("MAX31335 RTC driver");
697 MODULE_LICENSE("GPL");