rtc: rtc-sun4v fixes, revised

- simplified code
- use platform_driver_probe
- removed locking: it's provided by rtc subsystem

Signed-off-by: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by Alessandro Zummo and committed by David S. Miller cecf61bd e64ed022

+19 -50
+19 -50
drivers/rtc/rtc-sun4v.c
··· 1 - /* rtc-sun4c.c: Hypervisor based RTC for SUN4V systems. 2 * 3 * Copyright (C) 2008 David S. Miller <davem@davemloft.net> 4 */ ··· 7 #include <linux/module.h> 8 #include <linux/delay.h> 9 #include <linux/init.h> 10 - #include <linux/time.h> 11 #include <linux/rtc.h> 12 #include <linux/platform_device.h> 13 14 #include <asm/hypervisor.h> 15 - 16 - MODULE_AUTHOR("David S. Miller <davem@davemloft.net>"); 17 - MODULE_DESCRIPTION("SUN4V RTC driver"); 18 - MODULE_LICENSE("GPL"); 19 - 20 - struct sun4v_rtc { 21 - struct rtc_device *rtc; 22 - spinlock_t lock; 23 - }; 24 25 static unsigned long hypervisor_get_time(void) 26 { ··· 35 36 static int sun4v_read_time(struct device *dev, struct rtc_time *tm) 37 { 38 - struct sun4v_rtc *p = dev_get_drvdata(dev); 39 - unsigned long flags, secs; 40 - 41 - spin_lock_irqsave(&p->lock, flags); 42 - secs = hypervisor_get_time(); 43 - spin_unlock_irqrestore(&p->lock, flags); 44 - 45 - rtc_time_to_tm(secs, tm); 46 - 47 return 0; 48 } 49 ··· 62 63 static int sun4v_set_time(struct device *dev, struct rtc_time *tm) 64 { 65 - struct sun4v_rtc *p = dev_get_drvdata(dev); 66 - unsigned long flags, secs; 67 int err; 68 69 err = rtc_tm_to_time(tm, &secs); 70 if (err) 71 return err; 72 73 - spin_lock_irqsave(&p->lock, flags); 74 - err = hypervisor_set_time(secs); 75 - spin_unlock_irqrestore(&p->lock, flags); 76 - 77 - return err; 78 } 79 80 static const struct rtc_class_ops sun4v_rtc_ops = { ··· 77 .set_time = sun4v_set_time, 78 }; 79 80 - static int __devinit sun4v_rtc_probe(struct platform_device *pdev) 81 { 82 - struct sun4v_rtc *p = kzalloc(sizeof(*p), GFP_KERNEL); 83 - 84 - if (!p) 85 - return -ENOMEM; 86 - 87 - spin_lock_init(&p->lock); 88 - 89 - p->rtc = rtc_device_register("sun4v", &pdev->dev, 90 &sun4v_rtc_ops, THIS_MODULE); 91 - if (IS_ERR(p->rtc)) { 92 - int err = PTR_ERR(p->rtc); 93 - kfree(p); 94 - return err; 95 - } 96 - platform_set_drvdata(pdev, p); 97 return 0; 98 } 99 100 - static int __devexit sun4v_rtc_remove(struct platform_device *pdev) 101 { 102 - struct sun4v_rtc *p = platform_get_drvdata(pdev); 103 104 - rtc_device_unregister(p->rtc); 105 - kfree(p); 106 - 107 return 0; 108 } 109 ··· 101 .name = "rtc-sun4v", 102 .owner = THIS_MODULE, 103 }, 104 - .probe = sun4v_rtc_probe, 105 - .remove = __devexit_p(sun4v_rtc_remove), 106 }; 107 108 static int __init sun4v_rtc_init(void) 109 { 110 - return platform_driver_register(&sun4v_rtc_driver); 111 } 112 113 static void __exit sun4v_rtc_exit(void) ··· 116 117 module_init(sun4v_rtc_init); 118 module_exit(sun4v_rtc_exit);
··· 1 + /* rtc-sun4v.c: Hypervisor based RTC for SUN4V systems. 2 * 3 * Copyright (C) 2008 David S. Miller <davem@davemloft.net> 4 */ ··· 7 #include <linux/module.h> 8 #include <linux/delay.h> 9 #include <linux/init.h> 10 #include <linux/rtc.h> 11 #include <linux/platform_device.h> 12 13 #include <asm/hypervisor.h> 14 15 static unsigned long hypervisor_get_time(void) 16 { ··· 45 46 static int sun4v_read_time(struct device *dev, struct rtc_time *tm) 47 { 48 + rtc_time_to_tm(hypervisor_get_time(), tm); 49 return 0; 50 } 51 ··· 80 81 static int sun4v_set_time(struct device *dev, struct rtc_time *tm) 82 { 83 + unsigned long secs; 84 int err; 85 86 err = rtc_tm_to_time(tm, &secs); 87 if (err) 88 return err; 89 90 + return hypervisor_set_time(secs); 91 } 92 93 static const struct rtc_class_ops sun4v_rtc_ops = { ··· 100 .set_time = sun4v_set_time, 101 }; 102 103 + static int __init sun4v_rtc_probe(struct platform_device *pdev) 104 { 105 + struct rtc_device *rtc = rtc_device_register("sun4v", &pdev->dev, 106 &sun4v_rtc_ops, THIS_MODULE); 107 + if (IS_ERR(rtc)) 108 + return PTR_ERR(rtc); 109 + 110 + platform_set_drvdata(pdev, rtc); 111 return 0; 112 } 113 114 + static int __exit sun4v_rtc_remove(struct platform_device *pdev) 115 { 116 + struct rtc_device *rtc = platform_get_drvdata(pdev); 117 118 + rtc_device_unregister(rtc); 119 return 0; 120 } 121 ··· 135 .name = "rtc-sun4v", 136 .owner = THIS_MODULE, 137 }, 138 + .remove = __exit_p(sun4v_rtc_remove), 139 }; 140 141 static int __init sun4v_rtc_init(void) 142 { 143 + return platform_driver_probe(&sun4v_rtc_driver, sun4v_rtc_probe); 144 } 145 146 static void __exit sun4v_rtc_exit(void) ··· 151 152 module_init(sun4v_rtc_init); 153 module_exit(sun4v_rtc_exit); 154 + 155 + MODULE_AUTHOR("David S. Miller <davem@davemloft.net>"); 156 + MODULE_DESCRIPTION("SUN4V RTC driver"); 157 + MODULE_LICENSE("GPL");