hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/rtc/rtc-rv8803.c
....@@ -1,13 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * RTC driver for the Micro Crystal RV8803
34 *
45 * Copyright (C) 2015 Micro Crystal SA
5
- *
6
- * Alexandre Belloni <alexandre.belloni@free-electrons.com>
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License version 2 as
10
- * published by the Free Software Foundation.
6
+ * Alexandre Belloni <alexandre.belloni@bootlin.com>
117 *
128 */
139
....@@ -236,9 +232,6 @@
236232 u8 date[7];
237233 int ctrl, flags, ret;
238234
239
- if ((tm->tm_year < 100) || (tm->tm_year > 199))
240
- return -EINVAL;
241
-
242235 ctrl = rv8803_read_reg(rv8803->client, RV8803_CTRL);
243236 if (ctrl < 0)
244237 return ctrl;
....@@ -418,6 +411,7 @@
418411 {
419412 struct i2c_client *client = to_i2c_client(dev);
420413 struct rv8803_data *rv8803 = dev_get_drvdata(dev);
414
+ unsigned int vl = 0;
421415 int flags, ret = 0;
422416
423417 switch (cmd) {
....@@ -426,18 +420,15 @@
426420 if (flags < 0)
427421 return flags;
428422
429
- if (flags & RV8803_FLAG_V1F)
423
+ if (flags & RV8803_FLAG_V1F) {
430424 dev_warn(&client->dev, "Voltage low, temperature compensation stopped.\n");
425
+ vl = RTC_VL_ACCURACY_LOW;
426
+ }
431427
432428 if (flags & RV8803_FLAG_V2F)
433
- dev_warn(&client->dev, "Voltage low, data loss detected.\n");
429
+ vl |= RTC_VL_DATA_INVALID;
434430
435
- flags &= RV8803_FLAG_V1F | RV8803_FLAG_V2F;
436
-
437
- if (copy_to_user((void __user *)arg, &flags, sizeof(int)))
438
- return -EFAULT;
439
-
440
- return 0;
431
+ return put_user(vl, (unsigned int __user *)arg);
441432
442433 case RTC_VL_CLR:
443434 mutex_lock(&rv8803->flags_lock);
....@@ -447,7 +438,7 @@
447438 return flags;
448439 }
449440
450
- flags &= ~(RV8803_FLAG_V1F | RV8803_FLAG_V2F);
441
+ flags &= ~RV8803_FLAG_V1F;
451442 ret = rv8803_write_reg(client, RV8803_FLAG, flags);
452443 mutex_unlock(&rv8803->flags_lock);
453444 if (ret)
....@@ -463,13 +454,7 @@
463454 static int rv8803_nvram_write(void *priv, unsigned int offset, void *val,
464455 size_t bytes)
465456 {
466
- int ret;
467
-
468
- ret = rv8803_write_reg(priv, RV8803_RAM, *(u8 *)val);
469
- if (ret)
470
- return ret;
471
-
472
- return 0;
457
+ return rv8803_write_reg(priv, RV8803_RAM, *(u8 *)val);
473458 }
474459
475460 static int rv8803_nvram_read(void *priv, unsigned int offset,
....@@ -524,7 +509,7 @@
524509 static int rv8803_probe(struct i2c_client *client,
525510 const struct i2c_device_id *id)
526511 {
527
- struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
512
+ struct i2c_adapter *adapter = client->adapter;
528513 struct rv8803_data *rv8803;
529514 int err, flags;
530515 struct nvmem_config nvmem_cfg = {
....@@ -571,9 +556,8 @@
571556 dev_warn(&client->dev, "An alarm maybe have been missed.\n");
572557
573558 rv8803->rtc = devm_rtc_allocate_device(&client->dev);
574
- if (IS_ERR(rv8803->rtc)) {
559
+ if (IS_ERR(rv8803->rtc))
575560 return PTR_ERR(rv8803->rtc);
576
- }
577561
578562 if (client->irq > 0) {
579563 err = devm_request_threaded_irq(&client->dev, client->irq,
....@@ -602,6 +586,8 @@
602586
603587 rv8803->rtc->ops = &rv8803_rtc_ops;
604588 rv8803->rtc->nvram_old_abi = true;
589
+ rv8803->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
590
+ rv8803->rtc->range_max = RTC_TIMESTAMP_END_2099;
605591 err = rtc_register_device(rv8803->rtc);
606592 if (err)
607593 return err;
....@@ -615,6 +601,7 @@
615601
616602 static const struct i2c_device_id rv8803_id[] = {
617603 { "rv8803", rv_8803 },
604
+ { "rx8803", rv_8803 },
618605 { "rx8900", rx_8900 },
619606 { }
620607 };
....@@ -623,6 +610,10 @@
623610 static const struct of_device_id rv8803_of_match[] = {
624611 {
625612 .compatible = "microcrystal,rv8803",
613
+ .data = (void *)rv_8803
614
+ },
615
+ {
616
+ .compatible = "epson,rx8803",
626617 .data = (void *)rv_8803
627618 },
628619 {
....@@ -643,6 +634,6 @@
643634 };
644635 module_i2c_driver(rv8803_driver);
645636
646
-MODULE_AUTHOR("Alexandre Belloni <alexandre.belloni@free-electrons.com>");
637
+MODULE_AUTHOR("Alexandre Belloni <alexandre.belloni@bootlin.com>");
647638 MODULE_DESCRIPTION("Micro Crystal RV8803 RTC driver");
648639 MODULE_LICENSE("GPL v2");