Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rtc: sa1100: prepare to share sa1100_rtc_ops

Factor out the RTC initialization from the platform device specific
parts in order to share the RTC device ops with other drivers.
Specifically, it will be shared with rtc-pxa driver.

Signed-off-by: Rob Herring <robh@kernel.org>
Cc: Robert Jarzmik <robert.jarzmik@free.fr>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Cc: rtc-linux@googlegroups.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>

authored by

Rob Herring and committed by
Alexandre Belloni
8c0961ba dc2280eb

+49 -29
+30 -29
drivers/rtc/rtc-sa1100.c
··· 42 42 #include <mach/regs-rtc.h> 43 43 #endif 44 44 45 + #include "rtc-sa1100.h" 46 + 45 47 #define RTC_DEF_DIVIDER (32768 - 1) 46 48 #define RTC_DEF_TRIM 0 47 49 #define RTC_FREQ 1024 48 50 49 - struct sa1100_rtc { 50 - spinlock_t lock; 51 - int irq_1hz; 52 - int irq_alarm; 53 - struct rtc_device *rtc; 54 - struct clk *clk; 55 - }; 56 51 57 52 static irqreturn_t sa1100_rtc_interrupt(int irq, void *dev_id) 58 53 { ··· 218 223 .alarm_irq_enable = sa1100_rtc_alarm_irq_enable, 219 224 }; 220 225 221 - static int sa1100_rtc_probe(struct platform_device *pdev) 226 + int sa1100_rtc_init(struct platform_device *pdev, struct sa1100_rtc *info) 222 227 { 223 228 struct rtc_device *rtc; 224 - struct sa1100_rtc *info; 225 - int irq_1hz, irq_alarm, ret = 0; 229 + int ret; 226 230 227 - irq_1hz = platform_get_irq_byname(pdev, "rtc 1Hz"); 228 - irq_alarm = platform_get_irq_byname(pdev, "rtc alarm"); 229 - if (irq_1hz < 0 || irq_alarm < 0) 230 - return -ENODEV; 231 + spin_lock_init(&info->lock); 231 232 232 - info = devm_kzalloc(&pdev->dev, sizeof(struct sa1100_rtc), GFP_KERNEL); 233 - if (!info) 234 - return -ENOMEM; 235 233 info->clk = devm_clk_get(&pdev->dev, NULL); 236 234 if (IS_ERR(info->clk)) { 237 235 dev_err(&pdev->dev, "failed to find rtc clock source\n"); 238 236 return PTR_ERR(info->clk); 239 237 } 240 - info->irq_1hz = irq_1hz; 241 - info->irq_alarm = irq_alarm; 242 - spin_lock_init(&info->lock); 243 - platform_set_drvdata(pdev, info); 244 238 245 239 ret = clk_prepare_enable(info->clk); 246 240 if (ret) ··· 249 265 RCNR = 0; 250 266 } 251 267 252 - device_init_wakeup(&pdev->dev, 1); 253 - 254 268 rtc = devm_rtc_device_register(&pdev->dev, pdev->name, &sa1100_rtc_ops, 255 269 THIS_MODULE); 256 - 257 270 if (IS_ERR(rtc)) { 258 - ret = PTR_ERR(rtc); 259 - goto err_dev; 271 + clk_disable_unprepare(info->clk); 272 + return PTR_ERR(rtc); 260 273 } 261 274 info->rtc = rtc; 262 275 ··· 282 301 RTSR = RTSR_AL | RTSR_HZ; 283 302 284 303 return 0; 285 - err_dev: 286 - clk_disable_unprepare(info->clk); 287 - return ret; 304 + } 305 + EXPORT_SYMBOL_GPL(sa1100_rtc_init); 306 + 307 + static int sa1100_rtc_probe(struct platform_device *pdev) 308 + { 309 + struct sa1100_rtc *info; 310 + int irq_1hz, irq_alarm; 311 + 312 + irq_1hz = platform_get_irq_byname(pdev, "rtc 1Hz"); 313 + irq_alarm = platform_get_irq_byname(pdev, "rtc alarm"); 314 + if (irq_1hz < 0 || irq_alarm < 0) 315 + return -ENODEV; 316 + 317 + info = devm_kzalloc(&pdev->dev, sizeof(struct sa1100_rtc), GFP_KERNEL); 318 + if (!info) 319 + return -ENOMEM; 320 + info->irq_1hz = irq_1hz; 321 + info->irq_alarm = irq_alarm; 322 + 323 + platform_set_drvdata(pdev, info); 324 + device_init_wakeup(&pdev->dev, 1); 325 + 326 + return sa1100_rtc_init(pdev, info); 288 327 } 289 328 290 329 static int sa1100_rtc_remove(struct platform_device *pdev)
+19
drivers/rtc/rtc-sa1100.h
··· 1 + #ifndef __RTC_SA1100_H__ 2 + #define __RTC_SA1100_H__ 3 + 4 + #include <linux/kernel.h> 5 + 6 + struct clk; 7 + struct platform_device; 8 + 9 + struct sa1100_rtc { 10 + spinlock_t lock; 11 + int irq_1hz; 12 + int irq_alarm; 13 + struct rtc_device *rtc; 14 + struct clk *clk; 15 + }; 16 + 17 + int sa1100_rtc_init(struct platform_device *pdev, struct sa1100_rtc *info); 18 + 19 + #endif