diff options
Diffstat (limited to 'drivers/rtc/rtc-sh.c')
| -rw-r--r-- | drivers/rtc/rtc-sh.c | 97 |
1 files changed, 33 insertions, 64 deletions
diff --git a/drivers/rtc/rtc-sh.c b/drivers/rtc/rtc-sh.c index d7310adb7152..e6ed5404bca0 100644 --- a/drivers/rtc/rtc-sh.c +++ b/drivers/rtc/rtc-sh.c | |||
| @@ -29,7 +29,7 @@ | |||
| 29 | #include <asm/rtc.h> | 29 | #include <asm/rtc.h> |
| 30 | 30 | ||
| 31 | #define DRV_NAME "sh-rtc" | 31 | #define DRV_NAME "sh-rtc" |
| 32 | #define DRV_VERSION "0.2.2" | 32 | #define DRV_VERSION "0.2.3" |
| 33 | 33 | ||
| 34 | #define RTC_REG(r) ((r) * rtc_reg_size) | 34 | #define RTC_REG(r) ((r) * rtc_reg_size) |
| 35 | 35 | ||
| @@ -215,7 +215,7 @@ static irqreturn_t sh_rtc_shared(int irq, void *dev_id) | |||
| 215 | return IRQ_RETVAL(ret); | 215 | return IRQ_RETVAL(ret); |
| 216 | } | 216 | } |
| 217 | 217 | ||
| 218 | static inline void sh_rtc_setpie(struct device *dev, unsigned int enable) | 218 | static int sh_rtc_irq_set_state(struct device *dev, int enable) |
| 219 | { | 219 | { |
| 220 | struct sh_rtc *rtc = dev_get_drvdata(dev); | 220 | struct sh_rtc *rtc = dev_get_drvdata(dev); |
| 221 | unsigned int tmp; | 221 | unsigned int tmp; |
| @@ -225,17 +225,22 @@ static inline void sh_rtc_setpie(struct device *dev, unsigned int enable) | |||
| 225 | tmp = readb(rtc->regbase + RCR2); | 225 | tmp = readb(rtc->regbase + RCR2); |
| 226 | 226 | ||
| 227 | if (enable) { | 227 | if (enable) { |
| 228 | rtc->periodic_freq |= PF_KOU; | ||
| 228 | tmp &= ~RCR2_PEF; /* Clear PES bit */ | 229 | tmp &= ~RCR2_PEF; /* Clear PES bit */ |
| 229 | tmp |= (rtc->periodic_freq & ~PF_HP); /* Set PES2-0 */ | 230 | tmp |= (rtc->periodic_freq & ~PF_HP); /* Set PES2-0 */ |
| 230 | } else | 231 | } else { |
| 232 | rtc->periodic_freq &= ~PF_KOU; | ||
| 231 | tmp &= ~(RCR2_PESMASK | RCR2_PEF); | 233 | tmp &= ~(RCR2_PESMASK | RCR2_PEF); |
| 234 | } | ||
| 232 | 235 | ||
| 233 | writeb(tmp, rtc->regbase + RCR2); | 236 | writeb(tmp, rtc->regbase + RCR2); |
| 234 | 237 | ||
| 235 | spin_unlock_irq(&rtc->lock); | 238 | spin_unlock_irq(&rtc->lock); |
| 239 | |||
| 240 | return 0; | ||
| 236 | } | 241 | } |
| 237 | 242 | ||
| 238 | static inline int sh_rtc_setfreq(struct device *dev, unsigned int freq) | 243 | static int sh_rtc_irq_set_freq(struct device *dev, int freq) |
| 239 | { | 244 | { |
| 240 | struct sh_rtc *rtc = dev_get_drvdata(dev); | 245 | struct sh_rtc *rtc = dev_get_drvdata(dev); |
| 241 | int tmp, ret = 0; | 246 | int tmp, ret = 0; |
| @@ -278,10 +283,8 @@ static inline int sh_rtc_setfreq(struct device *dev, unsigned int freq) | |||
| 278 | ret = -ENOTSUPP; | 283 | ret = -ENOTSUPP; |
| 279 | } | 284 | } |
| 280 | 285 | ||
| 281 | if (ret == 0) { | 286 | if (ret == 0) |
| 282 | rtc->periodic_freq |= tmp; | 287 | rtc->periodic_freq |= tmp; |
| 283 | rtc->rtc_dev->irq_freq = freq; | ||
| 284 | } | ||
| 285 | 288 | ||
| 286 | spin_unlock_irq(&rtc->lock); | 289 | spin_unlock_irq(&rtc->lock); |
| 287 | return ret; | 290 | return ret; |
| @@ -346,10 +349,6 @@ static int sh_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) | |||
| 346 | unsigned int ret = 0; | 349 | unsigned int ret = 0; |
| 347 | 350 | ||
| 348 | switch (cmd) { | 351 | switch (cmd) { |
| 349 | case RTC_PIE_OFF: | ||
| 350 | case RTC_PIE_ON: | ||
| 351 | sh_rtc_setpie(dev, cmd == RTC_PIE_ON); | ||
| 352 | break; | ||
| 353 | case RTC_AIE_OFF: | 352 | case RTC_AIE_OFF: |
| 354 | case RTC_AIE_ON: | 353 | case RTC_AIE_ON: |
| 355 | sh_rtc_setaie(dev, cmd == RTC_AIE_ON); | 354 | sh_rtc_setaie(dev, cmd == RTC_AIE_ON); |
| @@ -362,13 +361,6 @@ static int sh_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) | |||
| 362 | rtc->periodic_freq |= PF_OXS; | 361 | rtc->periodic_freq |= PF_OXS; |
| 363 | sh_rtc_setcie(dev, 1); | 362 | sh_rtc_setcie(dev, 1); |
| 364 | break; | 363 | break; |
| 365 | case RTC_IRQP_READ: | ||
| 366 | ret = put_user(rtc->rtc_dev->irq_freq, | ||
| 367 | (unsigned long __user *)arg); | ||
| 368 | break; | ||
| 369 | case RTC_IRQP_SET: | ||
| 370 | ret = sh_rtc_setfreq(dev, arg); | ||
| 371 | break; | ||
| 372 | default: | 364 | default: |
| 373 | ret = -ENOIOCTLCMD; | 365 | ret = -ENOIOCTLCMD; |
| 374 | } | 366 | } |
| @@ -602,28 +594,6 @@ static int sh_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm) | |||
| 602 | return 0; | 594 | return 0; |
| 603 | } | 595 | } |
| 604 | 596 | ||
| 605 | static int sh_rtc_irq_set_state(struct device *dev, int enabled) | ||
| 606 | { | ||
| 607 | struct platform_device *pdev = to_platform_device(dev); | ||
| 608 | struct sh_rtc *rtc = platform_get_drvdata(pdev); | ||
| 609 | |||
| 610 | if (enabled) { | ||
| 611 | rtc->periodic_freq |= PF_KOU; | ||
| 612 | return sh_rtc_ioctl(dev, RTC_PIE_ON, 0); | ||
| 613 | } else { | ||
| 614 | rtc->periodic_freq &= ~PF_KOU; | ||
| 615 | return sh_rtc_ioctl(dev, RTC_PIE_OFF, 0); | ||
| 616 | } | ||
| 617 | } | ||
| 618 | |||
| 619 | static int sh_rtc_irq_set_freq(struct device *dev, int freq) | ||
| 620 | { | ||
| 621 | if (!is_power_of_2(freq)) | ||
| 622 | return -EINVAL; | ||
| 623 | |||
| 624 | return sh_rtc_ioctl(dev, RTC_IRQP_SET, freq); | ||
| 625 | } | ||
| 626 | |||
| 627 | static struct rtc_class_ops sh_rtc_ops = { | 597 | static struct rtc_class_ops sh_rtc_ops = { |
| 628 | .ioctl = sh_rtc_ioctl, | 598 | .ioctl = sh_rtc_ioctl, |
| 629 | .read_time = sh_rtc_read_time, | 599 | .read_time = sh_rtc_read_time, |
| @@ -635,7 +605,7 @@ static struct rtc_class_ops sh_rtc_ops = { | |||
| 635 | .proc = sh_rtc_proc, | 605 | .proc = sh_rtc_proc, |
| 636 | }; | 606 | }; |
| 637 | 607 | ||
| 638 | static int __devinit sh_rtc_probe(struct platform_device *pdev) | 608 | static int __init sh_rtc_probe(struct platform_device *pdev) |
| 639 | { | 609 | { |
| 640 | struct sh_rtc *rtc; | 610 | struct sh_rtc *rtc; |
| 641 | struct resource *res; | 611 | struct resource *res; |
| @@ -702,13 +672,6 @@ static int __devinit sh_rtc_probe(struct platform_device *pdev) | |||
| 702 | 672 | ||
| 703 | clk_enable(rtc->clk); | 673 | clk_enable(rtc->clk); |
| 704 | 674 | ||
| 705 | rtc->rtc_dev = rtc_device_register("sh", &pdev->dev, | ||
| 706 | &sh_rtc_ops, THIS_MODULE); | ||
| 707 | if (IS_ERR(rtc->rtc_dev)) { | ||
| 708 | ret = PTR_ERR(rtc->rtc_dev); | ||
| 709 | goto err_unmap; | ||
| 710 | } | ||
| 711 | |||
| 712 | rtc->capabilities = RTC_DEF_CAPABILITIES; | 675 | rtc->capabilities = RTC_DEF_CAPABILITIES; |
| 713 | if (pdev->dev.platform_data) { | 676 | if (pdev->dev.platform_data) { |
| 714 | struct sh_rtc_platform_info *pinfo = pdev->dev.platform_data; | 677 | struct sh_rtc_platform_info *pinfo = pdev->dev.platform_data; |
| @@ -720,10 +683,6 @@ static int __devinit sh_rtc_probe(struct platform_device *pdev) | |||
| 720 | rtc->capabilities |= pinfo->capabilities; | 683 | rtc->capabilities |= pinfo->capabilities; |
| 721 | } | 684 | } |
| 722 | 685 | ||
| 723 | rtc->rtc_dev->max_user_freq = 256; | ||
| 724 | |||
| 725 | platform_set_drvdata(pdev, rtc); | ||
| 726 | |||
| 727 | if (rtc->carry_irq <= 0) { | 686 | if (rtc->carry_irq <= 0) { |
| 728 | /* register shared periodic/carry/alarm irq */ | 687 | /* register shared periodic/carry/alarm irq */ |
| 729 | ret = request_irq(rtc->periodic_irq, sh_rtc_shared, | 688 | ret = request_irq(rtc->periodic_irq, sh_rtc_shared, |
| @@ -767,13 +726,26 @@ static int __devinit sh_rtc_probe(struct platform_device *pdev) | |||
| 767 | } | 726 | } |
| 768 | } | 727 | } |
| 769 | 728 | ||
| 729 | platform_set_drvdata(pdev, rtc); | ||
| 730 | |||
| 770 | /* everything disabled by default */ | 731 | /* everything disabled by default */ |
| 771 | rtc->periodic_freq = 0; | 732 | sh_rtc_irq_set_freq(&pdev->dev, 0); |
| 772 | rtc->rtc_dev->irq_freq = 0; | 733 | sh_rtc_irq_set_state(&pdev->dev, 0); |
| 773 | sh_rtc_setpie(&pdev->dev, 0); | ||
| 774 | sh_rtc_setaie(&pdev->dev, 0); | 734 | sh_rtc_setaie(&pdev->dev, 0); |
| 775 | sh_rtc_setcie(&pdev->dev, 0); | 735 | sh_rtc_setcie(&pdev->dev, 0); |
| 776 | 736 | ||
| 737 | rtc->rtc_dev = rtc_device_register("sh", &pdev->dev, | ||
| 738 | &sh_rtc_ops, THIS_MODULE); | ||
| 739 | if (IS_ERR(rtc->rtc_dev)) { | ||
| 740 | ret = PTR_ERR(rtc->rtc_dev); | ||
| 741 | free_irq(rtc->periodic_irq, rtc); | ||
| 742 | free_irq(rtc->carry_irq, rtc); | ||
| 743 | free_irq(rtc->alarm_irq, rtc); | ||
| 744 | goto err_unmap; | ||
| 745 | } | ||
| 746 | |||
| 747 | rtc->rtc_dev->max_user_freq = 256; | ||
| 748 | |||
| 777 | /* reset rtc to epoch 0 if time is invalid */ | 749 | /* reset rtc to epoch 0 if time is invalid */ |
| 778 | if (rtc_read_time(rtc->rtc_dev, &r) < 0) { | 750 | if (rtc_read_time(rtc->rtc_dev, &r) < 0) { |
| 779 | rtc_time_to_tm(0, &r); | 751 | rtc_time_to_tm(0, &r); |
| @@ -795,14 +767,13 @@ err_badres: | |||
| 795 | return ret; | 767 | return ret; |
| 796 | } | 768 | } |
| 797 | 769 | ||
| 798 | static int __devexit sh_rtc_remove(struct platform_device *pdev) | 770 | static int __exit sh_rtc_remove(struct platform_device *pdev) |
| 799 | { | 771 | { |
| 800 | struct sh_rtc *rtc = platform_get_drvdata(pdev); | 772 | struct sh_rtc *rtc = platform_get_drvdata(pdev); |
| 801 | 773 | ||
| 802 | if (likely(rtc->rtc_dev)) | 774 | rtc_device_unregister(rtc->rtc_dev); |
| 803 | rtc_device_unregister(rtc->rtc_dev); | 775 | sh_rtc_irq_set_state(&pdev->dev, 0); |
| 804 | 776 | ||
| 805 | sh_rtc_setpie(&pdev->dev, 0); | ||
| 806 | sh_rtc_setaie(&pdev->dev, 0); | 777 | sh_rtc_setaie(&pdev->dev, 0); |
| 807 | sh_rtc_setcie(&pdev->dev, 0); | 778 | sh_rtc_setcie(&pdev->dev, 0); |
| 808 | 779 | ||
| @@ -813,9 +784,8 @@ static int __devexit sh_rtc_remove(struct platform_device *pdev) | |||
| 813 | free_irq(rtc->alarm_irq, rtc); | 784 | free_irq(rtc->alarm_irq, rtc); |
| 814 | } | 785 | } |
| 815 | 786 | ||
| 816 | release_resource(rtc->res); | ||
| 817 | |||
| 818 | iounmap(rtc->regbase); | 787 | iounmap(rtc->regbase); |
| 788 | release_resource(rtc->res); | ||
| 819 | 789 | ||
| 820 | clk_disable(rtc->clk); | 790 | clk_disable(rtc->clk); |
| 821 | clk_put(rtc->clk); | 791 | clk_put(rtc->clk); |
| @@ -867,13 +837,12 @@ static struct platform_driver sh_rtc_platform_driver = { | |||
| 867 | .owner = THIS_MODULE, | 837 | .owner = THIS_MODULE, |
| 868 | .pm = &sh_rtc_dev_pm_ops, | 838 | .pm = &sh_rtc_dev_pm_ops, |
| 869 | }, | 839 | }, |
| 870 | .probe = sh_rtc_probe, | 840 | .remove = __exit_p(sh_rtc_remove), |
| 871 | .remove = __devexit_p(sh_rtc_remove), | ||
| 872 | }; | 841 | }; |
| 873 | 842 | ||
| 874 | static int __init sh_rtc_init(void) | 843 | static int __init sh_rtc_init(void) |
| 875 | { | 844 | { |
| 876 | return platform_driver_register(&sh_rtc_platform_driver); | 845 | return platform_driver_probe(&sh_rtc_platform_driver, sh_rtc_probe); |
| 877 | } | 846 | } |
| 878 | 847 | ||
| 879 | static void __exit sh_rtc_exit(void) | 848 | static void __exit sh_rtc_exit(void) |
