.. | .. |
---|
78 | 78 | int alarm_pending_status_reg; |
---|
79 | 79 | /* RTC IRQ CHIP for regmap */ |
---|
80 | 80 | const struct regmap_irq_chip *rtc_irq_chip; |
---|
| 81 | + /* regmap configuration for the chip */ |
---|
| 82 | + const struct regmap_config *regmap_config; |
---|
81 | 83 | }; |
---|
82 | 84 | |
---|
83 | 85 | struct max77686_rtc_info { |
---|
.. | .. |
---|
182 | 184 | .num_irqs = ARRAY_SIZE(max77686_rtc_irqs), |
---|
183 | 185 | }; |
---|
184 | 186 | |
---|
| 187 | +static const struct regmap_config max77686_rtc_regmap_config = { |
---|
| 188 | + .reg_bits = 8, |
---|
| 189 | + .val_bits = 8, |
---|
| 190 | +}; |
---|
| 191 | + |
---|
185 | 192 | static const struct max77686_rtc_driver_data max77686_drv_data = { |
---|
186 | 193 | .delay = 16000, |
---|
187 | 194 | .mask = 0x7f, |
---|
.. | .. |
---|
191 | 198 | .alarm_pending_status_reg = MAX77686_REG_STATUS2, |
---|
192 | 199 | .rtc_i2c_addr = MAX77686_I2C_ADDR_RTC, |
---|
193 | 200 | .rtc_irq_chip = &max77686_rtc_irq_chip, |
---|
| 201 | + .regmap_config = &max77686_rtc_regmap_config, |
---|
| 202 | +}; |
---|
| 203 | + |
---|
| 204 | +static const struct regmap_config max77620_rtc_regmap_config = { |
---|
| 205 | + .reg_bits = 8, |
---|
| 206 | + .val_bits = 8, |
---|
| 207 | + .use_single_write = true, |
---|
194 | 208 | }; |
---|
195 | 209 | |
---|
196 | 210 | static const struct max77686_rtc_driver_data max77620_drv_data = { |
---|
.. | .. |
---|
202 | 216 | .alarm_pending_status_reg = MAX77686_INVALID_REG, |
---|
203 | 217 | .rtc_i2c_addr = MAX77620_I2C_ADDR_RTC, |
---|
204 | 218 | .rtc_irq_chip = &max77686_rtc_irq_chip, |
---|
| 219 | + .regmap_config = &max77620_rtc_regmap_config, |
---|
205 | 220 | }; |
---|
206 | 221 | |
---|
207 | 222 | static const unsigned int max77802_map[REG_RTC_END] = { |
---|
.. | .. |
---|
658 | 673 | return ret; |
---|
659 | 674 | } |
---|
660 | 675 | |
---|
661 | | -static const struct regmap_config max77686_rtc_regmap_config = { |
---|
662 | | - .reg_bits = 8, |
---|
663 | | - .val_bits = 8, |
---|
664 | | -}; |
---|
665 | | - |
---|
666 | 676 | static int max77686_init_rtc_regmap(struct max77686_rtc_info *info) |
---|
667 | 677 | { |
---|
668 | 678 | struct device *parent = info->dev->parent; |
---|
.. | .. |
---|
673 | 683 | struct platform_device *pdev = to_platform_device(info->dev); |
---|
674 | 684 | |
---|
675 | 685 | info->rtc_irq = platform_get_irq(pdev, 0); |
---|
676 | | - if (info->rtc_irq < 0) { |
---|
677 | | - dev_err(info->dev, "Failed to get rtc interrupts: %d\n", |
---|
678 | | - info->rtc_irq); |
---|
| 686 | + if (info->rtc_irq < 0) |
---|
679 | 687 | return info->rtc_irq; |
---|
680 | | - } |
---|
681 | 688 | } else { |
---|
682 | 689 | info->rtc_irq = parent_i2c->irq; |
---|
683 | 690 | } |
---|
.. | .. |
---|
693 | 700 | goto add_rtc_irq; |
---|
694 | 701 | } |
---|
695 | 702 | |
---|
696 | | - info->rtc = i2c_new_dummy(parent_i2c->adapter, |
---|
697 | | - info->drv_data->rtc_i2c_addr); |
---|
698 | | - if (!info->rtc) { |
---|
| 703 | + info->rtc = devm_i2c_new_dummy_device(info->dev, parent_i2c->adapter, |
---|
| 704 | + info->drv_data->rtc_i2c_addr); |
---|
| 705 | + if (IS_ERR(info->rtc)) { |
---|
699 | 706 | dev_err(info->dev, "Failed to allocate I2C device for RTC\n"); |
---|
700 | | - return -ENODEV; |
---|
| 707 | + return PTR_ERR(info->rtc); |
---|
701 | 708 | } |
---|
702 | 709 | |
---|
703 | 710 | info->rtc_regmap = devm_regmap_init_i2c(info->rtc, |
---|
704 | | - &max77686_rtc_regmap_config); |
---|
| 711 | + info->drv_data->regmap_config); |
---|
705 | 712 | if (IS_ERR(info->rtc_regmap)) { |
---|
706 | 713 | ret = PTR_ERR(info->rtc_regmap); |
---|
707 | 714 | dev_err(info->dev, "Failed to allocate RTC regmap: %d\n", ret); |
---|
708 | | - goto err_unregister_i2c; |
---|
| 715 | + return ret; |
---|
709 | 716 | } |
---|
710 | 717 | |
---|
711 | 718 | add_rtc_irq: |
---|
.. | .. |
---|
715 | 722 | &info->rtc_irq_data); |
---|
716 | 723 | if (ret < 0) { |
---|
717 | 724 | dev_err(info->dev, "Failed to add RTC irq chip: %d\n", ret); |
---|
718 | | - goto err_unregister_i2c; |
---|
| 725 | + return ret; |
---|
719 | 726 | } |
---|
720 | 727 | |
---|
721 | 728 | return 0; |
---|
722 | | - |
---|
723 | | -err_unregister_i2c: |
---|
724 | | - if (info->rtc) |
---|
725 | | - i2c_unregister_device(info->rtc); |
---|
726 | | - return ret; |
---|
727 | 729 | } |
---|
728 | 730 | |
---|
729 | 731 | static int max77686_rtc_probe(struct platform_device *pdev) |
---|
.. | .. |
---|
786 | 788 | |
---|
787 | 789 | err_rtc: |
---|
788 | 790 | regmap_del_irq_chip(info->rtc_irq, info->rtc_irq_data); |
---|
789 | | - if (info->rtc) |
---|
790 | | - i2c_unregister_device(info->rtc); |
---|
791 | 791 | |
---|
792 | 792 | return ret; |
---|
793 | 793 | } |
---|
.. | .. |
---|
798 | 798 | |
---|
799 | 799 | free_irq(info->virq, info); |
---|
800 | 800 | regmap_del_irq_chip(info->rtc_irq, info->rtc_irq_data); |
---|
801 | | - if (info->rtc) |
---|
802 | | - i2c_unregister_device(info->rtc); |
---|
803 | 801 | |
---|
804 | 802 | return 0; |
---|
805 | 803 | } |
---|
.. | .. |
---|
807 | 805 | #ifdef CONFIG_PM_SLEEP |
---|
808 | 806 | static int max77686_rtc_suspend(struct device *dev) |
---|
809 | 807 | { |
---|
| 808 | + struct max77686_rtc_info *info = dev_get_drvdata(dev); |
---|
| 809 | + int ret = 0; |
---|
| 810 | + |
---|
810 | 811 | if (device_may_wakeup(dev)) { |
---|
811 | 812 | struct max77686_rtc_info *info = dev_get_drvdata(dev); |
---|
812 | 813 | |
---|
813 | | - return enable_irq_wake(info->virq); |
---|
| 814 | + ret = enable_irq_wake(info->virq); |
---|
814 | 815 | } |
---|
815 | 816 | |
---|
816 | | - return 0; |
---|
| 817 | + /* |
---|
| 818 | + * If the main IRQ (not virtual) is the parent IRQ, then it must be |
---|
| 819 | + * disabled during suspend because if it happens while suspended it |
---|
| 820 | + * will be handled before resuming I2C. |
---|
| 821 | + * |
---|
| 822 | + * Since Main IRQ is shared, all its users should disable it to be sure |
---|
| 823 | + * it won't fire while one of them is still suspended. |
---|
| 824 | + */ |
---|
| 825 | + if (!info->drv_data->rtc_irq_from_platform) |
---|
| 826 | + disable_irq(info->rtc_irq); |
---|
| 827 | + |
---|
| 828 | + return ret; |
---|
817 | 829 | } |
---|
818 | 830 | |
---|
819 | 831 | static int max77686_rtc_resume(struct device *dev) |
---|
820 | 832 | { |
---|
| 833 | + struct max77686_rtc_info *info = dev_get_drvdata(dev); |
---|
| 834 | + |
---|
| 835 | + if (!info->drv_data->rtc_irq_from_platform) |
---|
| 836 | + enable_irq(info->rtc_irq); |
---|
| 837 | + |
---|
821 | 838 | if (device_may_wakeup(dev)) { |
---|
822 | 839 | struct max77686_rtc_info *info = dev_get_drvdata(dev); |
---|
823 | 840 | |
---|