| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * RTC driver for Rockchip RK808 |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 5 | 6 | * |
|---|
| 6 | 7 | * Author: Chris Zhong <zyw@rock-chips.com> |
|---|
| 7 | 8 | * Author: Zhang Qing <zhangqing@rock-chips.com> |
|---|
| 8 | | - * |
|---|
| 9 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 10 | | - * under the terms and conditions of the GNU General Public License, |
|---|
| 11 | | - * version 2, as published by the Free Software Foundation. |
|---|
| 12 | | - * |
|---|
| 13 | | - * This program is distributed in the hope it will be useful, but WITHOUT |
|---|
| 14 | | - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|---|
| 15 | | - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
|---|
| 16 | | - * more details. |
|---|
| 17 | 9 | */ |
|---|
| 18 | 10 | |
|---|
| 19 | 11 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 36 | 28 | #define BIT_RTC_CTRL_REG_RTC_READSEL_M BIT(7) |
|---|
| 37 | 29 | #define BIT_RTC_INTERRUPTS_REG_IT_ALARM_M BIT(3) |
|---|
| 38 | 30 | #define RTC_STATUS_MASK 0xFE |
|---|
| 31 | +#define RTC_ALARM_STATUS BIT(6) |
|---|
| 39 | 32 | |
|---|
| 40 | 33 | #define SECONDS_REG_MSK 0x7F |
|---|
| 41 | 34 | #define MINUTES_REG_MAK 0x7F |
|---|
| .. | .. |
|---|
| 240 | 233 | return ret; |
|---|
| 241 | 234 | } |
|---|
| 242 | 235 | |
|---|
| 243 | | - dev_dbg(dev, "alrm read RTC date/time %4d-%02d-%02d(%d) %02d:%02d:%02d\n", |
|---|
| 244 | | - 1900 + alrm->time.tm_year, alrm->time.tm_mon + 1, |
|---|
| 245 | | - alrm->time.tm_mday, alrm->time.tm_wday, alrm->time.tm_hour, |
|---|
| 246 | | - alrm->time.tm_min, alrm->time.tm_sec); |
|---|
| 236 | + dev_dbg(dev, "alrm read RTC date/time %ptRd(%d) %ptRt\n", |
|---|
| 237 | + &alrm->time, alrm->time.tm_wday, &alrm->time); |
|---|
| 247 | 238 | |
|---|
| 248 | 239 | alrm->enabled = (int_reg & BIT_RTC_INTERRUPTS_REG_IT_ALARM_M) ? 1 : 0; |
|---|
| 249 | 240 | |
|---|
| .. | .. |
|---|
| 258 | 249 | ret = regmap_update_bits(rk808->regmap, rk808_rtc->creg->int_reg, |
|---|
| 259 | 250 | BIT_RTC_INTERRUPTS_REG_IT_ALARM_M, 0); |
|---|
| 260 | 251 | |
|---|
| 252 | + /* |
|---|
| 253 | + * The rtc alarm status(BIT(6)) must be cleared after alarm 1s or |
|---|
| 254 | + * after the alarm is disabled. |
|---|
| 255 | + */ |
|---|
| 256 | + ret = regmap_write(rk808->regmap, rk808_rtc->creg->status_reg, |
|---|
| 257 | + RTC_ALARM_STATUS); |
|---|
| 261 | 258 | return ret; |
|---|
| 262 | 259 | } |
|---|
| 263 | 260 | |
|---|
| .. | .. |
|---|
| 285 | 282 | dev_err(dev, "Failed to stop alarm: %d\n", ret); |
|---|
| 286 | 283 | return ret; |
|---|
| 287 | 284 | } |
|---|
| 288 | | - dev_dbg(dev, "alrm set RTC date/time %4d-%02d-%02d(%d) %02d:%02d:%02d\n", |
|---|
| 289 | | - 1900 + alrm->time.tm_year, alrm->time.tm_mon + 1, |
|---|
| 290 | | - alrm->time.tm_mday, alrm->time.tm_wday, alrm->time.tm_hour, |
|---|
| 291 | | - alrm->time.tm_min, alrm->time.tm_sec); |
|---|
| 285 | + dev_dbg(dev, "alrm set RTC date/time %ptRd(%d) %ptRt\n", |
|---|
| 286 | + &alrm->time, alrm->time.tm_wday, &alrm->time); |
|---|
| 292 | 287 | |
|---|
| 293 | 288 | if (rk808_rtc->flag & RTC_NEED_TRANSITIONS) |
|---|
| 294 | 289 | gregorian_to_rockchip(&alrm->time); |
|---|
| .. | .. |
|---|
| 371 | 366 | /* Turn off the alarm if it should not be a wake source. */ |
|---|
| 372 | 367 | static int rk808_rtc_suspend(struct device *dev) |
|---|
| 373 | 368 | { |
|---|
| 374 | | - struct platform_device *pdev = to_platform_device(dev); |
|---|
| 375 | | - struct rk808_rtc *rk808_rtc = dev_get_drvdata(&pdev->dev); |
|---|
| 369 | + struct rk808_rtc *rk808_rtc = dev_get_drvdata(dev); |
|---|
| 376 | 370 | |
|---|
| 377 | 371 | if (device_may_wakeup(dev)) |
|---|
| 378 | 372 | enable_irq_wake(rk808_rtc->irq); |
|---|
| .. | .. |
|---|
| 385 | 379 | */ |
|---|
| 386 | 380 | static int rk808_rtc_resume(struct device *dev) |
|---|
| 387 | 381 | { |
|---|
| 388 | | - struct platform_device *pdev = to_platform_device(dev); |
|---|
| 389 | | - struct rk808_rtc *rk808_rtc = dev_get_drvdata(&pdev->dev); |
|---|
| 382 | + struct rk808_rtc *rk808_rtc = dev_get_drvdata(dev); |
|---|
| 390 | 383 | |
|---|
| 391 | 384 | if (device_may_wakeup(dev)) |
|---|
| 392 | 385 | disable_irq_wake(rk808_rtc->irq); |
|---|
| .. | .. |
|---|
| 477 | 470 | if (ret) { |
|---|
| 478 | 471 | dev_err(&pdev->dev, |
|---|
| 479 | 472 | "Failed to write RTC status: %d\n", ret); |
|---|
| 480 | | - return ret; |
|---|
| 473 | + return ret; |
|---|
| 481 | 474 | } |
|---|
| 482 | 475 | |
|---|
| 483 | 476 | device_init_wakeup(&pdev->dev, 1); |
|---|
| .. | .. |
|---|
| 489 | 482 | rk808_rtc->rtc->ops = &rk808_rtc_ops; |
|---|
| 490 | 483 | |
|---|
| 491 | 484 | rk808_rtc->irq = platform_get_irq(pdev, 0); |
|---|
| 492 | | - if (rk808_rtc->irq < 0) { |
|---|
| 493 | | - if (rk808_rtc->irq != -EPROBE_DEFER) |
|---|
| 494 | | - dev_err(&pdev->dev, "Wake up is not possible as irq = %d\n", |
|---|
| 495 | | - rk808_rtc->irq); |
|---|
| 485 | + if (rk808_rtc->irq < 0) |
|---|
| 496 | 486 | return rk808_rtc->irq; |
|---|
| 497 | | - } |
|---|
| 498 | 487 | |
|---|
| 499 | 488 | /* request alarm irq of rk808 */ |
|---|
| 500 | 489 | ret = devm_request_threaded_irq(&pdev->dev, rk808_rtc->irq, NULL, |
|---|