diff options
Diffstat (limited to 'drivers/rtc/rtc-nuc900.c')
| -rw-r--r-- | drivers/rtc/rtc-nuc900.c | 72 |
1 files changed, 15 insertions, 57 deletions
diff --git a/drivers/rtc/rtc-nuc900.c b/drivers/rtc/rtc-nuc900.c index a63680850fef..f5dfb6e5e7d9 100644 --- a/drivers/rtc/rtc-nuc900.c +++ b/drivers/rtc/rtc-nuc900.c | |||
| @@ -222,13 +222,13 @@ static struct rtc_class_ops nuc900_rtc_ops = { | |||
| 222 | .alarm_irq_enable = nuc900_alarm_irq_enable, | 222 | .alarm_irq_enable = nuc900_alarm_irq_enable, |
| 223 | }; | 223 | }; |
| 224 | 224 | ||
| 225 | static int nuc900_rtc_probe(struct platform_device *pdev) | 225 | static int __init nuc900_rtc_probe(struct platform_device *pdev) |
| 226 | { | 226 | { |
| 227 | struct resource *res; | 227 | struct resource *res; |
| 228 | struct nuc900_rtc *nuc900_rtc; | 228 | struct nuc900_rtc *nuc900_rtc; |
| 229 | int err = 0; | ||
| 230 | 229 | ||
| 231 | nuc900_rtc = kzalloc(sizeof(struct nuc900_rtc), GFP_KERNEL); | 230 | nuc900_rtc = devm_kzalloc(&pdev->dev, sizeof(struct nuc900_rtc), |
| 231 | GFP_KERNEL); | ||
| 232 | if (!nuc900_rtc) { | 232 | if (!nuc900_rtc) { |
| 233 | dev_err(&pdev->dev, "kzalloc nuc900_rtc failed\n"); | 233 | dev_err(&pdev->dev, "kzalloc nuc900_rtc failed\n"); |
| 234 | return -ENOMEM; | 234 | return -ENOMEM; |
| @@ -236,93 +236,51 @@ static int nuc900_rtc_probe(struct platform_device *pdev) | |||
| 236 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 236 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 237 | if (!res) { | 237 | if (!res) { |
| 238 | dev_err(&pdev->dev, "platform_get_resource failed\n"); | 238 | dev_err(&pdev->dev, "platform_get_resource failed\n"); |
| 239 | err = -ENXIO; | 239 | return -ENXIO; |
| 240 | goto fail1; | ||
| 241 | } | 240 | } |
| 242 | 241 | ||
| 243 | if (!request_mem_region(res->start, resource_size(res), | 242 | nuc900_rtc->rtc_reg = devm_ioremap_resource(&pdev->dev, res); |
| 244 | pdev->name)) { | 243 | if (IS_ERR(nuc900_rtc->rtc_reg)) |
| 245 | dev_err(&pdev->dev, "request_mem_region failed\n"); | 244 | return PTR_ERR(nuc900_rtc->rtc_reg); |
| 246 | err = -EBUSY; | ||
| 247 | goto fail1; | ||
| 248 | } | ||
| 249 | |||
| 250 | nuc900_rtc->rtc_reg = ioremap(res->start, resource_size(res)); | ||
| 251 | if (!nuc900_rtc->rtc_reg) { | ||
| 252 | dev_err(&pdev->dev, "ioremap rtc_reg failed\n"); | ||
| 253 | err = -ENOMEM; | ||
| 254 | goto fail2; | ||
| 255 | } | ||
| 256 | 245 | ||
| 257 | platform_set_drvdata(pdev, nuc900_rtc); | 246 | platform_set_drvdata(pdev, nuc900_rtc); |
| 258 | 247 | ||
| 259 | nuc900_rtc->rtcdev = rtc_device_register(pdev->name, &pdev->dev, | 248 | nuc900_rtc->rtcdev = devm_rtc_device_register(&pdev->dev, pdev->name, |
| 260 | &nuc900_rtc_ops, THIS_MODULE); | 249 | &nuc900_rtc_ops, THIS_MODULE); |
| 261 | if (IS_ERR(nuc900_rtc->rtcdev)) { | 250 | if (IS_ERR(nuc900_rtc->rtcdev)) { |
| 262 | dev_err(&pdev->dev, "rtc device register failed\n"); | 251 | dev_err(&pdev->dev, "rtc device register failed\n"); |
| 263 | err = PTR_ERR(nuc900_rtc->rtcdev); | 252 | return PTR_ERR(nuc900_rtc->rtcdev); |
| 264 | goto fail3; | ||
| 265 | } | 253 | } |
| 266 | 254 | ||
| 267 | __raw_writel(__raw_readl(nuc900_rtc->rtc_reg + REG_RTC_TSSR) | MODE24, | 255 | __raw_writel(__raw_readl(nuc900_rtc->rtc_reg + REG_RTC_TSSR) | MODE24, |
| 268 | nuc900_rtc->rtc_reg + REG_RTC_TSSR); | 256 | nuc900_rtc->rtc_reg + REG_RTC_TSSR); |
| 269 | 257 | ||
| 270 | nuc900_rtc->irq_num = platform_get_irq(pdev, 0); | 258 | nuc900_rtc->irq_num = platform_get_irq(pdev, 0); |
| 271 | if (request_irq(nuc900_rtc->irq_num, nuc900_rtc_interrupt, | 259 | if (devm_request_irq(&pdev->dev, nuc900_rtc->irq_num, |
| 272 | 0, "nuc900rtc", nuc900_rtc)) { | 260 | nuc900_rtc_interrupt, 0, "nuc900rtc", nuc900_rtc)) { |
| 273 | dev_err(&pdev->dev, "NUC900 RTC request irq failed\n"); | 261 | dev_err(&pdev->dev, "NUC900 RTC request irq failed\n"); |
| 274 | err = -EBUSY; | 262 | return -EBUSY; |
| 275 | goto fail4; | ||
| 276 | } | 263 | } |
| 277 | 264 | ||
| 278 | return 0; | 265 | return 0; |
| 279 | |||
| 280 | fail4: rtc_device_unregister(nuc900_rtc->rtcdev); | ||
| 281 | fail3: iounmap(nuc900_rtc->rtc_reg); | ||
| 282 | fail2: release_mem_region(res->start, resource_size(res)); | ||
| 283 | fail1: kfree(nuc900_rtc); | ||
| 284 | return err; | ||
| 285 | } | 266 | } |
| 286 | 267 | ||
| 287 | static int nuc900_rtc_remove(struct platform_device *pdev) | 268 | static int __exit nuc900_rtc_remove(struct platform_device *pdev) |
| 288 | { | 269 | { |
| 289 | struct nuc900_rtc *nuc900_rtc = platform_get_drvdata(pdev); | ||
| 290 | struct resource *res; | ||
| 291 | |||
| 292 | free_irq(nuc900_rtc->irq_num, nuc900_rtc); | ||
| 293 | rtc_device_unregister(nuc900_rtc->rtcdev); | ||
| 294 | iounmap(nuc900_rtc->rtc_reg); | ||
| 295 | |||
| 296 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
| 297 | release_mem_region(res->start, resource_size(res)); | ||
| 298 | |||
| 299 | kfree(nuc900_rtc); | ||
| 300 | |||
| 301 | platform_set_drvdata(pdev, NULL); | 270 | platform_set_drvdata(pdev, NULL); |
| 302 | 271 | ||
| 303 | return 0; | 272 | return 0; |
| 304 | } | 273 | } |
| 305 | 274 | ||
| 306 | static struct platform_driver nuc900_rtc_driver = { | 275 | static struct platform_driver nuc900_rtc_driver = { |
| 307 | .remove = nuc900_rtc_remove, | 276 | .remove = __exit_p(nuc900_rtc_remove), |
| 308 | .driver = { | 277 | .driver = { |
| 309 | .name = "nuc900-rtc", | 278 | .name = "nuc900-rtc", |
| 310 | .owner = THIS_MODULE, | 279 | .owner = THIS_MODULE, |
| 311 | }, | 280 | }, |
| 312 | }; | 281 | }; |
| 313 | 282 | ||
| 314 | static int __init nuc900_rtc_init(void) | 283 | module_platform_driver_probe(nuc900_rtc_driver, nuc900_rtc_probe); |
| 315 | { | ||
| 316 | return platform_driver_probe(&nuc900_rtc_driver, nuc900_rtc_probe); | ||
| 317 | } | ||
| 318 | |||
| 319 | static void __exit nuc900_rtc_exit(void) | ||
| 320 | { | ||
| 321 | platform_driver_unregister(&nuc900_rtc_driver); | ||
| 322 | } | ||
| 323 | |||
| 324 | module_init(nuc900_rtc_init); | ||
| 325 | module_exit(nuc900_rtc_exit); | ||
| 326 | 284 | ||
| 327 | MODULE_AUTHOR("Wan ZongShun <mcuos.com@gmail.com>"); | 285 | MODULE_AUTHOR("Wan ZongShun <mcuos.com@gmail.com>"); |
| 328 | MODULE_DESCRIPTION("nuc910/nuc920 RTC driver"); | 286 | MODULE_DESCRIPTION("nuc910/nuc920 RTC driver"); |
