diff options
Diffstat (limited to 'drivers/rtc/rtc-ds3232.c')
-rw-r--r-- | drivers/rtc/rtc-ds3232.c | 167 |
1 files changed, 164 insertions, 3 deletions
diff --git a/drivers/rtc/rtc-ds3232.c b/drivers/rtc/rtc-ds3232.c index 5791f996fa32..ca43bfcbb846 100644 --- a/drivers/rtc/rtc-ds3232.c +++ b/drivers/rtc/rtc-ds3232.c | |||
@@ -1,8 +1,9 @@ | |||
1 | /* | 1 | /* |
2 | * RTC client/driver for the Maxim/Dallas DS3232 Real-Time Clock over I2C | 2 | * RTC client/driver for the Maxim/Dallas DS3232/DS3234 Real-Time Clock |
3 | * | 3 | * |
4 | * Copyright (C) 2009-2011 Freescale Semiconductor. | 4 | * Copyright (C) 2009-2011 Freescale Semiconductor. |
5 | * Author: Jack Lan <jack.lan@freescale.com> | 5 | * Author: Jack Lan <jack.lan@freescale.com> |
6 | * Copyright (C) 2008 MIMOMax Wireless Ltd. | ||
6 | * | 7 | * |
7 | * This program is free software; you can redistribute it and/or modify it | 8 | * This program is free software; you can redistribute it and/or modify it |
8 | * under the terms of the GNU General Public License as published by the | 9 | * under the terms of the GNU General Public License as published by the |
@@ -16,6 +17,7 @@ | |||
16 | #include <linux/module.h> | 17 | #include <linux/module.h> |
17 | #include <linux/interrupt.h> | 18 | #include <linux/interrupt.h> |
18 | #include <linux/i2c.h> | 19 | #include <linux/i2c.h> |
20 | #include <linux/spi/spi.h> | ||
19 | #include <linux/rtc.h> | 21 | #include <linux/rtc.h> |
20 | #include <linux/bcd.h> | 22 | #include <linux/bcd.h> |
21 | #include <linux/workqueue.h> | 23 | #include <linux/workqueue.h> |
@@ -481,6 +483,8 @@ static const struct dev_pm_ops ds3232_pm_ops = { | |||
481 | SET_SYSTEM_SLEEP_PM_OPS(ds3232_suspend, ds3232_resume) | 483 | SET_SYSTEM_SLEEP_PM_OPS(ds3232_suspend, ds3232_resume) |
482 | }; | 484 | }; |
483 | 485 | ||
486 | #if IS_ENABLED(CONFIG_I2C) | ||
487 | |||
484 | static int ds3232_i2c_probe(struct i2c_client *client, | 488 | static int ds3232_i2c_probe(struct i2c_client *client, |
485 | const struct i2c_device_id *id) | 489 | const struct i2c_device_id *id) |
486 | { | 490 | { |
@@ -520,8 +524,165 @@ static struct i2c_driver ds3232_driver = { | |||
520 | .remove = ds3232_i2c_remove, | 524 | .remove = ds3232_i2c_remove, |
521 | .id_table = ds3232_id, | 525 | .id_table = ds3232_id, |
522 | }; | 526 | }; |
523 | module_i2c_driver(ds3232_driver); | 527 | |
528 | static int ds3232_register_driver(void) | ||
529 | { | ||
530 | return i2c_add_driver(&ds3232_driver); | ||
531 | } | ||
532 | |||
533 | static void ds3232_unregister_driver(void) | ||
534 | { | ||
535 | i2c_del_driver(&ds3232_driver); | ||
536 | } | ||
537 | |||
538 | #else | ||
539 | |||
540 | static int ds3232_register_driver(void) | ||
541 | { | ||
542 | return 0; | ||
543 | } | ||
544 | |||
545 | static void ds3232_unregister_driver(void) | ||
546 | { | ||
547 | } | ||
548 | |||
549 | #endif | ||
550 | |||
551 | #if IS_ENABLED(CONFIG_SPI_MASTER) | ||
552 | |||
553 | static int ds3234_probe(struct spi_device *spi) | ||
554 | { | ||
555 | int res; | ||
556 | unsigned int tmp; | ||
557 | static const struct regmap_config config = { | ||
558 | .reg_bits = 8, | ||
559 | .val_bits = 8, | ||
560 | .write_flag_mask = 0x80, | ||
561 | }; | ||
562 | struct regmap *regmap; | ||
563 | |||
564 | regmap = devm_regmap_init_spi(spi, &config); | ||
565 | if (IS_ERR(regmap)) { | ||
566 | dev_err(&spi->dev, "%s: regmap allocation failed: %ld\n", | ||
567 | __func__, PTR_ERR(regmap)); | ||
568 | return PTR_ERR(regmap); | ||
569 | } | ||
570 | |||
571 | spi->mode = SPI_MODE_3; | ||
572 | spi->bits_per_word = 8; | ||
573 | spi_setup(spi); | ||
574 | |||
575 | res = regmap_read(regmap, DS3232_REG_SECONDS, &tmp); | ||
576 | if (res) | ||
577 | return res; | ||
578 | |||
579 | /* Control settings | ||
580 | * | ||
581 | * CONTROL_REG | ||
582 | * BIT 7 6 5 4 3 2 1 0 | ||
583 | * EOSC BBSQW CONV RS2 RS1 INTCN A2IE A1IE | ||
584 | * | ||
585 | * 0 0 0 1 1 1 0 0 | ||
586 | * | ||
587 | * CONTROL_STAT_REG | ||
588 | * BIT 7 6 5 4 3 2 1 0 | ||
589 | * OSF BB32kHz CRATE1 CRATE0 EN32kHz BSY A2F A1F | ||
590 | * | ||
591 | * 1 0 0 0 1 0 0 0 | ||
592 | */ | ||
593 | res = regmap_read(regmap, DS3232_REG_CR, &tmp); | ||
594 | if (res) | ||
595 | return res; | ||
596 | res = regmap_write(regmap, DS3232_REG_CR, tmp & 0x1c); | ||
597 | if (res) | ||
598 | return res; | ||
599 | |||
600 | res = regmap_read(regmap, DS3232_REG_SR, &tmp); | ||
601 | if (res) | ||
602 | return res; | ||
603 | res = regmap_write(regmap, DS3232_REG_SR, tmp & 0x88); | ||
604 | if (res) | ||
605 | return res; | ||
606 | |||
607 | /* Print our settings */ | ||
608 | res = regmap_read(regmap, DS3232_REG_CR, &tmp); | ||
609 | if (res) | ||
610 | return res; | ||
611 | dev_info(&spi->dev, "Control Reg: 0x%02x\n", tmp); | ||
612 | |||
613 | res = regmap_read(regmap, DS3232_REG_SR, &tmp); | ||
614 | if (res) | ||
615 | return res; | ||
616 | dev_info(&spi->dev, "Ctrl/Stat Reg: 0x%02x\n", tmp); | ||
617 | |||
618 | return ds3232_probe(&spi->dev, regmap, spi->irq, "ds3234"); | ||
619 | } | ||
620 | |||
621 | static int ds3234_remove(struct spi_device *spi) | ||
622 | { | ||
623 | return ds3232_remove(&spi->dev); | ||
624 | } | ||
625 | |||
626 | static struct spi_driver ds3234_driver = { | ||
627 | .driver = { | ||
628 | .name = "ds3234", | ||
629 | }, | ||
630 | .probe = ds3234_probe, | ||
631 | .remove = ds3234_remove, | ||
632 | }; | ||
633 | |||
634 | static int ds3234_register_driver(void) | ||
635 | { | ||
636 | return spi_register_driver(&ds3234_driver); | ||
637 | } | ||
638 | |||
639 | static void ds3234_unregister_driver(void) | ||
640 | { | ||
641 | spi_unregister_driver(&ds3234_driver); | ||
642 | } | ||
643 | |||
644 | #else | ||
645 | |||
646 | static int ds3234_register_driver(void) | ||
647 | { | ||
648 | return 0; | ||
649 | } | ||
650 | |||
651 | static void ds3234_unregister_driver(void) | ||
652 | { | ||
653 | } | ||
654 | |||
655 | #endif | ||
656 | |||
657 | static int __init ds323x_init(void) | ||
658 | { | ||
659 | int ret; | ||
660 | |||
661 | ret = ds3232_register_driver(); | ||
662 | if (ret) { | ||
663 | pr_err("Failed to register ds3232 driver: %d\n", ret); | ||
664 | return ret; | ||
665 | } | ||
666 | |||
667 | ret = ds3234_register_driver(); | ||
668 | if (ret) { | ||
669 | pr_err("Failed to register ds3234 driver: %d\n", ret); | ||
670 | ds3232_unregister_driver(); | ||
671 | } | ||
672 | |||
673 | return ret; | ||
674 | } | ||
675 | module_init(ds323x_init) | ||
676 | |||
677 | static void __exit ds323x_exit(void) | ||
678 | { | ||
679 | ds3234_unregister_driver(); | ||
680 | ds3232_unregister_driver(); | ||
681 | } | ||
682 | module_exit(ds323x_exit) | ||
524 | 683 | ||
525 | MODULE_AUTHOR("Srikanth Srinivasan <srikanth.srinivasan@freescale.com>"); | 684 | MODULE_AUTHOR("Srikanth Srinivasan <srikanth.srinivasan@freescale.com>"); |
526 | MODULE_DESCRIPTION("Maxim/Dallas DS3232 RTC Driver"); | 685 | MODULE_AUTHOR("Dennis Aberilla <denzzzhome@yahoo.com>"); |
686 | MODULE_DESCRIPTION("Maxim/Dallas DS3232/DS3234 RTC Driver"); | ||
527 | MODULE_LICENSE("GPL"); | 687 | MODULE_LICENSE("GPL"); |
688 | MODULE_ALIAS("spi:ds3234"); | ||