| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Real-time clock driver for MPC5121 |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright 2007, Domen Puncer <domen.puncer@telargo.com> |
|---|
| 5 | 6 | * Copyright 2008, Freescale Semiconductor, Inc. All rights reserved. |
|---|
| 6 | 7 | * Copyright 2011, Dmitry Eremin-Solenikov |
|---|
| 7 | | - * |
|---|
| 8 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 9 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 10 | | - * published by the Free Software Foundation. |
|---|
| 11 | 8 | */ |
|---|
| 12 | 9 | |
|---|
| 13 | 10 | #include <linux/init.h> |
|---|
| .. | .. |
|---|
| 114 | 111 | */ |
|---|
| 115 | 112 | now = in_be32(®s->actual_time) + in_be32(®s->target_time); |
|---|
| 116 | 113 | |
|---|
| 117 | | - rtc_time_to_tm(now, tm); |
|---|
| 114 | + rtc_time64_to_tm(now, tm); |
|---|
| 118 | 115 | |
|---|
| 119 | 116 | /* |
|---|
| 120 | 117 | * update second minute hour registers |
|---|
| .. | .. |
|---|
| 129 | 126 | { |
|---|
| 130 | 127 | struct mpc5121_rtc_data *rtc = dev_get_drvdata(dev); |
|---|
| 131 | 128 | struct mpc5121_rtc_regs __iomem *regs = rtc->regs; |
|---|
| 132 | | - int ret; |
|---|
| 133 | 129 | unsigned long now; |
|---|
| 134 | 130 | |
|---|
| 135 | 131 | /* |
|---|
| 136 | 132 | * The actual_time register is read only so we write the offset |
|---|
| 137 | 133 | * between it and linux time to the target_time register. |
|---|
| 138 | 134 | */ |
|---|
| 139 | | - ret = rtc_tm_to_time(tm, &now); |
|---|
| 140 | | - if (ret == 0) |
|---|
| 141 | | - out_be32(®s->target_time, now - in_be32(®s->actual_time)); |
|---|
| 135 | + now = rtc_tm_to_time64(tm); |
|---|
| 136 | + out_be32(®s->target_time, now - in_be32(®s->actual_time)); |
|---|
| 142 | 137 | |
|---|
| 143 | 138 | /* |
|---|
| 144 | 139 | * update second minute hour registers |
|---|
| .. | .. |
|---|
| 318 | 313 | if (!rtc) |
|---|
| 319 | 314 | return -ENOMEM; |
|---|
| 320 | 315 | |
|---|
| 321 | | - rtc->regs = of_iomap(op->dev.of_node, 0); |
|---|
| 322 | | - if (!rtc->regs) { |
|---|
| 316 | + rtc->regs = devm_platform_ioremap_resource(op, 0); |
|---|
| 317 | + if (IS_ERR(rtc->regs)) { |
|---|
| 323 | 318 | dev_err(&op->dev, "%s: couldn't map io space\n", __func__); |
|---|
| 324 | | - return -ENOSYS; |
|---|
| 319 | + return PTR_ERR(rtc->regs); |
|---|
| 325 | 320 | } |
|---|
| 326 | 321 | |
|---|
| 327 | 322 | device_init_wakeup(&op->dev, 1); |
|---|
| .. | .. |
|---|
| 329 | 324 | platform_set_drvdata(op, rtc); |
|---|
| 330 | 325 | |
|---|
| 331 | 326 | rtc->irq = irq_of_parse_and_map(op->dev.of_node, 1); |
|---|
| 332 | | - err = request_irq(rtc->irq, mpc5121_rtc_handler, 0, |
|---|
| 333 | | - "mpc5121-rtc", &op->dev); |
|---|
| 327 | + err = devm_request_irq(&op->dev, rtc->irq, mpc5121_rtc_handler, 0, |
|---|
| 328 | + "mpc5121-rtc", &op->dev); |
|---|
| 334 | 329 | if (err) { |
|---|
| 335 | 330 | dev_err(&op->dev, "%s: could not request irq: %i\n", |
|---|
| 336 | 331 | __func__, rtc->irq); |
|---|
| .. | .. |
|---|
| 338 | 333 | } |
|---|
| 339 | 334 | |
|---|
| 340 | 335 | rtc->irq_periodic = irq_of_parse_and_map(op->dev.of_node, 0); |
|---|
| 341 | | - err = request_irq(rtc->irq_periodic, mpc5121_rtc_handler_upd, |
|---|
| 342 | | - 0, "mpc5121-rtc_upd", &op->dev); |
|---|
| 336 | + err = devm_request_irq(&op->dev, rtc->irq_periodic, |
|---|
| 337 | + mpc5121_rtc_handler_upd, 0, "mpc5121-rtc_upd", |
|---|
| 338 | + &op->dev); |
|---|
| 343 | 339 | if (err) { |
|---|
| 344 | 340 | dev_err(&op->dev, "%s: could not request irq: %i\n", |
|---|
| 345 | 341 | __func__, rtc->irq_periodic); |
|---|
| 346 | 342 | goto out_dispose2; |
|---|
| 347 | 343 | } |
|---|
| 344 | + |
|---|
| 345 | + rtc->rtc = devm_rtc_allocate_device(&op->dev); |
|---|
| 346 | + if (IS_ERR(rtc->rtc)) { |
|---|
| 347 | + err = PTR_ERR(rtc->rtc); |
|---|
| 348 | + goto out_dispose2; |
|---|
| 349 | + } |
|---|
| 350 | + |
|---|
| 351 | + rtc->rtc->ops = &mpc5200_rtc_ops; |
|---|
| 352 | + rtc->rtc->uie_unsupported = 1; |
|---|
| 353 | + rtc->rtc->range_min = RTC_TIMESTAMP_BEGIN_0000; |
|---|
| 354 | + rtc->rtc->range_max = 65733206399ULL; /* 4052-12-31 23:59:59 */ |
|---|
| 348 | 355 | |
|---|
| 349 | 356 | if (of_device_is_compatible(op->dev.of_node, "fsl,mpc5121-rtc")) { |
|---|
| 350 | 357 | u32 ka; |
|---|
| .. | .. |
|---|
| 354 | 361 | "mpc5121-rtc: Battery or oscillator failure!\n"); |
|---|
| 355 | 362 | out_be32(&rtc->regs->keep_alive, ka); |
|---|
| 356 | 363 | } |
|---|
| 357 | | - |
|---|
| 358 | | - rtc->rtc = devm_rtc_device_register(&op->dev, "mpc5121-rtc", |
|---|
| 359 | | - &mpc5121_rtc_ops, THIS_MODULE); |
|---|
| 360 | | - } else { |
|---|
| 361 | | - rtc->rtc = devm_rtc_device_register(&op->dev, "mpc5200-rtc", |
|---|
| 362 | | - &mpc5200_rtc_ops, THIS_MODULE); |
|---|
| 364 | + rtc->rtc->ops = &mpc5121_rtc_ops; |
|---|
| 365 | + /* |
|---|
| 366 | + * This is a limitation of the driver that abuses the target |
|---|
| 367 | + * time register, the actual maximum year for the mpc5121 is |
|---|
| 368 | + * also 4052. |
|---|
| 369 | + */ |
|---|
| 370 | + rtc->rtc->range_min = 0; |
|---|
| 371 | + rtc->rtc->range_max = U32_MAX; |
|---|
| 363 | 372 | } |
|---|
| 364 | 373 | |
|---|
| 365 | | - if (IS_ERR(rtc->rtc)) { |
|---|
| 366 | | - err = PTR_ERR(rtc->rtc); |
|---|
| 367 | | - goto out_free_irq; |
|---|
| 368 | | - } |
|---|
| 369 | | - rtc->rtc->uie_unsupported = 1; |
|---|
| 374 | + err = rtc_register_device(rtc->rtc); |
|---|
| 375 | + if (err) |
|---|
| 376 | + goto out_dispose2; |
|---|
| 370 | 377 | |
|---|
| 371 | 378 | return 0; |
|---|
| 372 | 379 | |
|---|
| 373 | | -out_free_irq: |
|---|
| 374 | | - free_irq(rtc->irq_periodic, &op->dev); |
|---|
| 375 | 380 | out_dispose2: |
|---|
| 376 | 381 | irq_dispose_mapping(rtc->irq_periodic); |
|---|
| 377 | | - free_irq(rtc->irq, &op->dev); |
|---|
| 378 | 382 | out_dispose: |
|---|
| 379 | 383 | irq_dispose_mapping(rtc->irq); |
|---|
| 380 | | - iounmap(rtc->regs); |
|---|
| 381 | 384 | |
|---|
| 382 | 385 | return err; |
|---|
| 383 | 386 | } |
|---|
| .. | .. |
|---|
| 391 | 394 | out_8(®s->alm_enable, 0); |
|---|
| 392 | 395 | out_8(®s->int_enable, in_8(®s->int_enable) & ~0x1); |
|---|
| 393 | 396 | |
|---|
| 394 | | - iounmap(rtc->regs); |
|---|
| 395 | | - free_irq(rtc->irq, &op->dev); |
|---|
| 396 | | - free_irq(rtc->irq_periodic, &op->dev); |
|---|
| 397 | 397 | irq_dispose_mapping(rtc->irq); |
|---|
| 398 | 398 | irq_dispose_mapping(rtc->irq_periodic); |
|---|
| 399 | 399 | |
|---|