| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0+ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Real Time Clock driver for Wolfson Microelectronics WM831x |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2009 Wolfson Microelectronics PLC. |
|---|
| 5 | 6 | * |
|---|
| 6 | 7 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> |
|---|
| 7 | | - * |
|---|
| 8 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 9 | | - * under the terms of the GNU General Public License as published by the |
|---|
| 10 | | - * Free Software Foundation; either version 2 of the License, or (at your |
|---|
| 11 | | - * option) any later version. |
|---|
| 12 | 8 | * |
|---|
| 13 | 9 | */ |
|---|
| 14 | 10 | |
|---|
| .. | .. |
|---|
| 155 | 151 | if (memcmp(time1, time2, sizeof(time1)) == 0) { |
|---|
| 156 | 152 | u32 time = (time1[0] << 16) | time1[1]; |
|---|
| 157 | 153 | |
|---|
| 158 | | - rtc_time_to_tm(time, tm); |
|---|
| 154 | + rtc_time64_to_tm(time, tm); |
|---|
| 159 | 155 | return 0; |
|---|
| 160 | 156 | } |
|---|
| 161 | 157 | |
|---|
| .. | .. |
|---|
| 169 | 165 | /* |
|---|
| 170 | 166 | * Set current time and date in RTC |
|---|
| 171 | 167 | */ |
|---|
| 172 | | -static int wm831x_rtc_set_mmss(struct device *dev, unsigned long time) |
|---|
| 168 | +static int wm831x_rtc_settime(struct device *dev, struct rtc_time *tm) |
|---|
| 173 | 169 | { |
|---|
| 174 | 170 | struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(dev); |
|---|
| 175 | 171 | struct wm831x *wm831x = wm831x_rtc->wm831x; |
|---|
| 176 | 172 | struct rtc_time new_tm; |
|---|
| 177 | | - unsigned long new_time; |
|---|
| 173 | + unsigned long time, new_time; |
|---|
| 178 | 174 | int ret; |
|---|
| 179 | 175 | int count = 0; |
|---|
| 176 | + |
|---|
| 177 | + time = rtc_tm_to_time64(tm); |
|---|
| 180 | 178 | |
|---|
| 181 | 179 | ret = wm831x_reg_write(wm831x, WM831X_RTC_TIME_1, |
|---|
| 182 | 180 | (time >> 16) & 0xffff); |
|---|
| .. | .. |
|---|
| 215 | 213 | if (ret < 0) |
|---|
| 216 | 214 | return ret; |
|---|
| 217 | 215 | |
|---|
| 218 | | - ret = rtc_tm_to_time(&new_tm, &new_time); |
|---|
| 219 | | - if (ret < 0) { |
|---|
| 220 | | - dev_err(dev, "Failed to convert time: %d\n", ret); |
|---|
| 221 | | - return ret; |
|---|
| 222 | | - } |
|---|
| 216 | + new_time = rtc_tm_to_time64(&new_tm); |
|---|
| 223 | 217 | |
|---|
| 224 | 218 | /* Allow a second of change in case of tick */ |
|---|
| 225 | 219 | if (new_time - time > 1) { |
|---|
| .. | .. |
|---|
| 249 | 243 | |
|---|
| 250 | 244 | time = (data[0] << 16) | data[1]; |
|---|
| 251 | 245 | |
|---|
| 252 | | - rtc_time_to_tm(time, &alrm->time); |
|---|
| 246 | + rtc_time64_to_tm(time, &alrm->time); |
|---|
| 253 | 247 | |
|---|
| 254 | 248 | ret = wm831x_reg_read(wm831x_rtc->wm831x, WM831X_RTC_CONTROL); |
|---|
| 255 | 249 | if (ret < 0) { |
|---|
| .. | .. |
|---|
| 288 | 282 | int ret; |
|---|
| 289 | 283 | unsigned long time; |
|---|
| 290 | 284 | |
|---|
| 291 | | - ret = rtc_tm_to_time(&alrm->time, &time); |
|---|
| 292 | | - if (ret < 0) { |
|---|
| 293 | | - dev_err(dev, "Failed to convert time: %d\n", ret); |
|---|
| 294 | | - return ret; |
|---|
| 295 | | - } |
|---|
| 285 | + time = rtc_tm_to_time64(&alrm->time); |
|---|
| 296 | 286 | |
|---|
| 297 | 287 | ret = wm831x_rtc_stop_alarm(wm831x_rtc); |
|---|
| 298 | 288 | if (ret < 0) { |
|---|
| .. | .. |
|---|
| 346 | 336 | |
|---|
| 347 | 337 | static const struct rtc_class_ops wm831x_rtc_ops = { |
|---|
| 348 | 338 | .read_time = wm831x_rtc_readtime, |
|---|
| 349 | | - .set_mmss = wm831x_rtc_set_mmss, |
|---|
| 339 | + .set_time = wm831x_rtc_settime, |
|---|
| 350 | 340 | .read_alarm = wm831x_rtc_readalarm, |
|---|
| 351 | 341 | .set_alarm = wm831x_rtc_setalarm, |
|---|
| 352 | 342 | .alarm_irq_enable = wm831x_rtc_alarm_irq_enable, |
|---|
| .. | .. |
|---|
| 356 | 346 | /* Turn off the alarm if it should not be a wake source. */ |
|---|
| 357 | 347 | static int wm831x_rtc_suspend(struct device *dev) |
|---|
| 358 | 348 | { |
|---|
| 359 | | - struct platform_device *pdev = to_platform_device(dev); |
|---|
| 360 | | - struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(&pdev->dev); |
|---|
| 349 | + struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(dev); |
|---|
| 361 | 350 | int ret, enable; |
|---|
| 362 | 351 | |
|---|
| 363 | | - if (wm831x_rtc->alarm_enabled && device_may_wakeup(&pdev->dev)) |
|---|
| 352 | + if (wm831x_rtc->alarm_enabled && device_may_wakeup(dev)) |
|---|
| 364 | 353 | enable = WM831X_RTC_ALM_ENA; |
|---|
| 365 | 354 | else |
|---|
| 366 | 355 | enable = 0; |
|---|
| .. | .. |
|---|
| 368 | 357 | ret = wm831x_set_bits(wm831x_rtc->wm831x, WM831X_RTC_CONTROL, |
|---|
| 369 | 358 | WM831X_RTC_ALM_ENA, enable); |
|---|
| 370 | 359 | if (ret != 0) |
|---|
| 371 | | - dev_err(&pdev->dev, "Failed to update RTC alarm: %d\n", ret); |
|---|
| 360 | + dev_err(dev, "Failed to update RTC alarm: %d\n", ret); |
|---|
| 372 | 361 | |
|---|
| 373 | 362 | return 0; |
|---|
| 374 | 363 | } |
|---|
| .. | .. |
|---|
| 378 | 367 | */ |
|---|
| 379 | 368 | static int wm831x_rtc_resume(struct device *dev) |
|---|
| 380 | 369 | { |
|---|
| 381 | | - struct platform_device *pdev = to_platform_device(dev); |
|---|
| 382 | | - struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(&pdev->dev); |
|---|
| 370 | + struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(dev); |
|---|
| 383 | 371 | int ret; |
|---|
| 384 | 372 | |
|---|
| 385 | 373 | if (wm831x_rtc->alarm_enabled) { |
|---|
| 386 | 374 | ret = wm831x_rtc_start_alarm(wm831x_rtc); |
|---|
| 387 | 375 | if (ret != 0) |
|---|
| 388 | | - dev_err(&pdev->dev, |
|---|
| 389 | | - "Failed to restart RTC alarm: %d\n", ret); |
|---|
| 376 | + dev_err(dev, "Failed to restart RTC alarm: %d\n", ret); |
|---|
| 390 | 377 | } |
|---|
| 391 | 378 | |
|---|
| 392 | 379 | return 0; |
|---|
| .. | .. |
|---|
| 395 | 382 | /* Unconditionally disable the alarm */ |
|---|
| 396 | 383 | static int wm831x_rtc_freeze(struct device *dev) |
|---|
| 397 | 384 | { |
|---|
| 398 | | - struct platform_device *pdev = to_platform_device(dev); |
|---|
| 399 | | - struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(&pdev->dev); |
|---|
| 385 | + struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(dev); |
|---|
| 400 | 386 | int ret; |
|---|
| 401 | 387 | |
|---|
| 402 | 388 | ret = wm831x_set_bits(wm831x_rtc->wm831x, WM831X_RTC_CONTROL, |
|---|
| 403 | 389 | WM831X_RTC_ALM_ENA, 0); |
|---|
| 404 | 390 | if (ret != 0) |
|---|
| 405 | | - dev_err(&pdev->dev, "Failed to stop RTC alarm: %d\n", ret); |
|---|
| 391 | + dev_err(dev, "Failed to stop RTC alarm: %d\n", ret); |
|---|
| 406 | 392 | |
|---|
| 407 | 393 | return 0; |
|---|
| 408 | 394 | } |
|---|
| .. | .. |
|---|
| 429 | 415 | ret = wm831x_reg_read(wm831x, WM831X_RTC_CONTROL); |
|---|
| 430 | 416 | if (ret < 0) { |
|---|
| 431 | 417 | dev_err(&pdev->dev, "Failed to read RTC control: %d\n", ret); |
|---|
| 432 | | - goto err; |
|---|
| 418 | + return ret; |
|---|
| 433 | 419 | } |
|---|
| 434 | 420 | if (ret & WM831X_RTC_ALM_ENA) |
|---|
| 435 | 421 | wm831x_rtc->alarm_enabled = 1; |
|---|
| 436 | 422 | |
|---|
| 437 | 423 | device_init_wakeup(&pdev->dev, 1); |
|---|
| 438 | 424 | |
|---|
| 439 | | - wm831x_rtc->rtc = devm_rtc_device_register(&pdev->dev, "wm831x", |
|---|
| 440 | | - &wm831x_rtc_ops, THIS_MODULE); |
|---|
| 441 | | - if (IS_ERR(wm831x_rtc->rtc)) { |
|---|
| 442 | | - ret = PTR_ERR(wm831x_rtc->rtc); |
|---|
| 443 | | - goto err; |
|---|
| 444 | | - } |
|---|
| 425 | + wm831x_rtc->rtc = devm_rtc_allocate_device(&pdev->dev); |
|---|
| 426 | + if (IS_ERR(wm831x_rtc->rtc)) |
|---|
| 427 | + return PTR_ERR(wm831x_rtc->rtc); |
|---|
| 428 | + |
|---|
| 429 | + wm831x_rtc->rtc->ops = &wm831x_rtc_ops; |
|---|
| 430 | + wm831x_rtc->rtc->range_max = U32_MAX; |
|---|
| 431 | + |
|---|
| 432 | + ret = rtc_register_device(wm831x_rtc->rtc); |
|---|
| 433 | + if (ret) |
|---|
| 434 | + return ret; |
|---|
| 445 | 435 | |
|---|
| 446 | 436 | ret = devm_request_threaded_irq(&pdev->dev, alm_irq, NULL, |
|---|
| 447 | 437 | wm831x_alm_irq, |
|---|
| 448 | | - IRQF_TRIGGER_RISING, "RTC alarm", |
|---|
| 438 | + IRQF_TRIGGER_RISING | IRQF_ONESHOT, |
|---|
| 439 | + "RTC alarm", |
|---|
| 449 | 440 | wm831x_rtc); |
|---|
| 450 | 441 | if (ret != 0) { |
|---|
| 451 | 442 | dev_err(&pdev->dev, "Failed to request alarm IRQ %d: %d\n", |
|---|
| .. | .. |
|---|
| 455 | 446 | wm831x_rtc_add_randomness(wm831x); |
|---|
| 456 | 447 | |
|---|
| 457 | 448 | return 0; |
|---|
| 458 | | - |
|---|
| 459 | | -err: |
|---|
| 460 | | - return ret; |
|---|
| 461 | 449 | } |
|---|
| 462 | 450 | |
|---|
| 463 | 451 | static const struct dev_pm_ops wm831x_rtc_pm_ops = { |
|---|