hc
2024-05-10 ee930fffee469d076998274a2ca55e13dc1efb67
kernel/drivers/rtc/rtc-s35390a.c
....@@ -1,12 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Seiko Instruments S-35390A RTC Driver
34 *
45 * Copyright (c) 2007 Byron Bradley
5
- *
6
- * This program is free software; you can redistribute it and/or
7
- * modify it under the terms of the GNU General Public License
8
- * as published by the Free Software Foundation; either version
9
- * 2 of the License, or (at your option) any later version.
106 */
117
128 #include <linux/module.h>
....@@ -36,21 +32,22 @@
3632 #define S35390A_ALRM_BYTE_MINS 2
3733
3834 /* flags for STATUS1 */
39
-#define S35390A_FLAG_POC 0x01
40
-#define S35390A_FLAG_BLD 0x02
41
-#define S35390A_FLAG_INT2 0x04
42
-#define S35390A_FLAG_24H 0x40
43
-#define S35390A_FLAG_RESET 0x80
35
+#define S35390A_FLAG_POC BIT(0)
36
+#define S35390A_FLAG_BLD BIT(1)
37
+#define S35390A_FLAG_INT2 BIT(2)
38
+#define S35390A_FLAG_24H BIT(6)
39
+#define S35390A_FLAG_RESET BIT(7)
4440
4541 /* flag for STATUS2 */
46
-#define S35390A_FLAG_TEST 0x01
42
+#define S35390A_FLAG_TEST BIT(0)
4743
48
-#define S35390A_INT2_MODE_MASK 0xF0
49
-
44
+/* INT2 pin output mode */
45
+#define S35390A_INT2_MODE_MASK 0x0E
5046 #define S35390A_INT2_MODE_NOINTR 0x00
51
-#define S35390A_INT2_MODE_FREQ 0x10
52
-#define S35390A_INT2_MODE_ALARM 0x40
53
-#define S35390A_INT2_MODE_PMIN_EDG 0x20
47
+#define S35390A_INT2_MODE_ALARM BIT(1) /* INT2AE */
48
+#define S35390A_INT2_MODE_PMIN_EDG BIT(2) /* INT2ME */
49
+#define S35390A_INT2_MODE_FREQ BIT(3) /* INT2FE */
50
+#define S35390A_INT2_MODE_PMIN (BIT(3) | BIT(2)) /* INT2FE | INT2ME */
5451
5552 static const struct i2c_device_id s35390a_id[] = {
5653 { "s35390a", 0 },
....@@ -288,6 +285,9 @@
288285 alm->time.tm_min, alm->time.tm_hour, alm->time.tm_mday,
289286 alm->time.tm_mon, alm->time.tm_year, alm->time.tm_wday);
290287
288
+ if (alm->time.tm_sec != 0)
289
+ dev_warn(&client->dev, "Alarms are only supported on a per minute basis!\n");
290
+
291291 /* disable interrupt (which deasserts the irq line) */
292292 err = s35390a_set_reg(s35390a, S35390A_CMD_STATUS2, &sts, sizeof(sts));
293293 if (err < 0)
....@@ -302,9 +302,6 @@
302302 sts = S35390A_INT2_MODE_ALARM;
303303 else
304304 sts = S35390A_INT2_MODE_NOINTR;
305
-
306
- /* This chip expects the bits of each byte to be in reverse order */
307
- sts = bitrev8(sts);
308305
309306 /* set interupt mode*/
310307 err = s35390a_set_reg(s35390a, S35390A_CMD_STATUS2, &sts, sizeof(sts));
....@@ -343,7 +340,7 @@
343340 if (err < 0)
344341 return err;
345342
346
- if ((bitrev8(sts) & S35390A_INT2_MODE_MASK) != S35390A_INT2_MODE_ALARM) {
343
+ if ((sts & S35390A_INT2_MODE_MASK) != S35390A_INT2_MODE_ALARM) {
347344 /*
348345 * When the alarm isn't enabled, the register to configure
349346 * the alarm time isn't accessible.
....@@ -426,8 +423,6 @@
426423 .ioctl = s35390a_rtc_ioctl,
427424 };
428425
429
-static struct i2c_driver s35390a_driver;
430
-
431426 static int s35390a_probe(struct i2c_client *client,
432427 const struct i2c_device_id *id)
433428 {
....@@ -435,39 +430,38 @@
435430 unsigned int i;
436431 struct s35390a *s35390a;
437432 char buf, status1;
433
+ struct device *dev = &client->dev;
438434
439
- if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
440
- err = -ENODEV;
441
- goto exit;
442
- }
435
+ if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
436
+ return -ENODEV;
443437
444
- s35390a = devm_kzalloc(&client->dev, sizeof(struct s35390a),
445
- GFP_KERNEL);
446
- if (!s35390a) {
447
- err = -ENOMEM;
448
- goto exit;
449
- }
438
+ s35390a = devm_kzalloc(dev, sizeof(struct s35390a), GFP_KERNEL);
439
+ if (!s35390a)
440
+ return -ENOMEM;
450441
451442 s35390a->client[0] = client;
452443 i2c_set_clientdata(client, s35390a);
453444
454445 /* This chip uses multiple addresses, use dummy devices for them */
455446 for (i = 1; i < 8; ++i) {
456
- s35390a->client[i] = i2c_new_dummy(client->adapter,
457
- client->addr + i);
458
- if (!s35390a->client[i]) {
459
- dev_err(&client->dev, "Address %02x unavailable\n",
460
- client->addr + i);
461
- err = -EBUSY;
462
- goto exit_dummy;
447
+ s35390a->client[i] = devm_i2c_new_dummy_device(dev,
448
+ client->adapter,
449
+ client->addr + i);
450
+ if (IS_ERR(s35390a->client[i])) {
451
+ dev_err(dev, "Address %02x unavailable\n",
452
+ client->addr + i);
453
+ return PTR_ERR(s35390a->client[i]);
463454 }
464455 }
465456
457
+ s35390a->rtc = devm_rtc_allocate_device(dev);
458
+ if (IS_ERR(s35390a->rtc))
459
+ return PTR_ERR(s35390a->rtc);
460
+
466461 err_read = s35390a_read_status(s35390a, &status1);
467462 if (err_read < 0) {
468
- err = err_read;
469
- dev_err(&client->dev, "error resetting chip\n");
470
- goto exit_dummy;
463
+ dev_err(dev, "error resetting chip\n");
464
+ return err_read;
471465 }
472466
473467 if (status1 & S35390A_FLAG_24H)
....@@ -480,52 +474,30 @@
480474 buf = 0;
481475 err = s35390a_set_reg(s35390a, S35390A_CMD_STATUS2, &buf, 1);
482476 if (err < 0) {
483
- dev_err(&client->dev, "error disabling alarm");
484
- goto exit_dummy;
477
+ dev_err(dev, "error disabling alarm");
478
+ return err;
485479 }
486480 } else {
487481 err = s35390a_disable_test_mode(s35390a);
488482 if (err < 0) {
489
- dev_err(&client->dev, "error disabling test mode\n");
490
- goto exit_dummy;
483
+ dev_err(dev, "error disabling test mode\n");
484
+ return err;
491485 }
492486 }
493487
494
- device_set_wakeup_capable(&client->dev, 1);
488
+ device_set_wakeup_capable(dev, 1);
495489
496
- s35390a->rtc = devm_rtc_device_register(&client->dev,
497
- s35390a_driver.driver.name,
498
- &s35390a_rtc_ops, THIS_MODULE);
490
+ s35390a->rtc->ops = &s35390a_rtc_ops;
491
+ s35390a->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
492
+ s35390a->rtc->range_max = RTC_TIMESTAMP_END_2099;
499493
500
- if (IS_ERR(s35390a->rtc)) {
501
- err = PTR_ERR(s35390a->rtc);
502
- goto exit_dummy;
503
- }
494
+ /* supports per-minute alarms only, therefore set uie_unsupported */
495
+ s35390a->rtc->uie_unsupported = 1;
504496
505497 if (status1 & S35390A_FLAG_INT2)
506498 rtc_update_irq(s35390a->rtc, 1, RTC_AF);
507499
508
- return 0;
509
-
510
-exit_dummy:
511
- for (i = 1; i < 8; ++i)
512
- if (s35390a->client[i])
513
- i2c_unregister_device(s35390a->client[i]);
514
-
515
-exit:
516
- return err;
517
-}
518
-
519
-static int s35390a_remove(struct i2c_client *client)
520
-{
521
- unsigned int i;
522
- struct s35390a *s35390a = i2c_get_clientdata(client);
523
-
524
- for (i = 1; i < 8; ++i)
525
- if (s35390a->client[i])
526
- i2c_unregister_device(s35390a->client[i]);
527
-
528
- return 0;
500
+ return rtc_register_device(s35390a->rtc);
529501 }
530502
531503 static struct i2c_driver s35390a_driver = {
....@@ -534,7 +506,6 @@
534506 .of_match_table = of_match_ptr(s35390a_of_match),
535507 },
536508 .probe = s35390a_probe,
537
- .remove = s35390a_remove,
538509 .id_table = s35390a_id,
539510 };
540511