hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/rtc/rtc-m41t80.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * I2C client/driver for the ST M41T80 family of i2c rtc chips.
34 *
....@@ -6,11 +7,6 @@
67 * Based on m41t00.c by Mark A. Greer <mgreer@mvista.com>
78 *
89 * 2006 (c) mycable GmbH
9
- *
10
- * This program is free software; you can redistribute it and/or modify
11
- * it under the terms of the GNU General Public License version 2 as
12
- * published by the Free Software Foundation.
13
- *
1410 */
1511
1612 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
....@@ -217,7 +213,7 @@
217213 sizeof(buf), buf);
218214 if (err < 0) {
219215 dev_err(&client->dev, "Unable to read date\n");
220
- return -EIO;
216
+ return err;
221217 }
222218
223219 tm->tm_sec = bcd2bin(buf[M41T80_REG_SEC] & 0x7f);
....@@ -238,9 +234,6 @@
238234 struct m41t80_data *clientdata = i2c_get_clientdata(client);
239235 unsigned char buf[8];
240236 int err, flags;
241
-
242
- if (tm->tm_year < 100 || tm->tm_year > 199)
243
- return -EINVAL;
244237
245238 buf[M41T80_REG_SSEC] = 0;
246239 buf[M41T80_REG_SEC] = bin2bcd(tm->tm_sec);
....@@ -274,10 +267,11 @@
274267 if (flags < 0)
275268 return flags;
276269
277
- if (i2c_smbus_write_byte_data(client, M41T80_REG_FLAGS,
278
- flags & ~M41T80_FLAGS_OF)) {
270
+ err = i2c_smbus_write_byte_data(client, M41T80_REG_FLAGS,
271
+ flags & ~M41T80_FLAGS_OF);
272
+ if (err < 0) {
279273 dev_err(&client->dev, "Unable to write flags register\n");
280
- return -EIO;
274
+ return err;
281275 }
282276
283277 return err;
....@@ -287,10 +281,12 @@
287281 {
288282 struct i2c_client *client = to_i2c_client(dev);
289283 struct m41t80_data *clientdata = i2c_get_clientdata(client);
290
- u8 reg;
284
+ int reg;
291285
292286 if (clientdata->features & M41T80_FEATURE_BL) {
293287 reg = i2c_smbus_read_byte_data(client, M41T80_REG_FLAGS);
288
+ if (reg < 0)
289
+ return reg;
294290 seq_printf(seq, "battery\t\t: %s\n",
295291 (reg & M41T80_FLAGS_BATT_LOW) ? "exhausted" : "ok");
296292 }
....@@ -706,7 +702,6 @@
706702
707703 /**
708704 * wdt_ioctl:
709
- * @inode: inode of the device
710705 * @file: file handle to the device
711706 * @cmd: watchdog command
712707 * @arg: argument pointer
....@@ -745,7 +740,7 @@
745740 return -EINVAL;
746741 wdt_margin = new_margin;
747742 wdt_ping();
748
- /* Fall */
743
+ fallthrough;
749744 case WDIOC_GETTIMEOUT:
750745 return put_user(wdt_margin, (int __user *)arg);
751746
....@@ -799,7 +794,7 @@
799794 */
800795 wdt_is_open = 1;
801796 mutex_unlock(&m41t80_rtc_mutex);
802
- return nonseekable_open(inode, file);
797
+ return stream_open(inode, file);
803798 }
804799 return -ENODEV;
805800 }
....@@ -841,6 +836,7 @@
841836 .owner = THIS_MODULE,
842837 .read = wdt_read,
843838 .unlocked_ioctl = wdt_unlocked_ioctl,
839
+ .compat_ioctl = compat_ptr_ioctl,
844840 .write = wdt_write,
845841 .open = wdt_open,
846842 .release = wdt_release,
....@@ -873,7 +869,7 @@
873869 static int m41t80_probe(struct i2c_client *client,
874870 const struct i2c_device_id *id)
875871 {
876
- struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
872
+ struct i2c_adapter *adapter = client->adapter;
877873 int rc = 0;
878874 struct rtc_time tm;
879875 struct m41t80_data *m41t80_data = NULL;
....@@ -926,6 +922,8 @@
926922 }
927923
928924 m41t80_data->rtc->ops = &m41t80_rtc_ops;
925
+ m41t80_data->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
926
+ m41t80_data->rtc->range_max = RTC_TIMESTAMP_END_2099;
929927
930928 if (client->irq <= 0) {
931929 /* We cannot support UIE mode if we do not have an IRQ line */
....@@ -939,11 +937,7 @@
939937 if (m41t80_data->features & M41T80_FEATURE_HT) {
940938 m41t80_rtc_read_time(&client->dev, &tm);
941939 dev_info(&client->dev, "HT bit was set!\n");
942
- dev_info(&client->dev,
943
- "Power Down at %04i-%02i-%02i %02i:%02i:%02i\n",
944
- tm.tm_year + 1900,
945
- tm.tm_mon + 1, tm.tm_mday, tm.tm_hour,
946
- tm.tm_min, tm.tm_sec);
940
+ dev_info(&client->dev, "Power Down at %ptR\n", &tm);
947941 }
948942 rc = i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_HOUR,
949943 rc & ~M41T80_ALHOUR_HT);