| .. | .. |
|---|
| 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 |
|---|
| 39 | | -#define RTC_ALARM_STATUS BIT(6) |
|---|
| 40 | 31 | |
|---|
| 41 | 32 | #define SECONDS_REG_MSK 0x7F |
|---|
| 42 | 33 | #define MINUTES_REG_MAK 0x7F |
|---|
| .. | .. |
|---|
| 241 | 232 | return ret; |
|---|
| 242 | 233 | } |
|---|
| 243 | 234 | |
|---|
| 244 | | - dev_dbg(dev, "alrm read RTC date/time %4d-%02d-%02d(%d) %02d:%02d:%02d\n", |
|---|
| 245 | | - 1900 + alrm->time.tm_year, alrm->time.tm_mon + 1, |
|---|
| 246 | | - alrm->time.tm_mday, alrm->time.tm_wday, alrm->time.tm_hour, |
|---|
| 247 | | - alrm->time.tm_min, alrm->time.tm_sec); |
|---|
| 235 | + dev_dbg(dev, "alrm read RTC date/time %ptRd(%d) %ptRt\n", |
|---|
| 236 | + &alrm->time, alrm->time.tm_wday, &alrm->time); |
|---|
| 248 | 237 | |
|---|
| 249 | 238 | alrm->enabled = (int_reg & BIT_RTC_INTERRUPTS_REG_IT_ALARM_M) ? 1 : 0; |
|---|
| 250 | 239 | |
|---|
| .. | .. |
|---|
| 259 | 248 | ret = regmap_update_bits(rk808->regmap, rk808_rtc->creg->int_reg, |
|---|
| 260 | 249 | BIT_RTC_INTERRUPTS_REG_IT_ALARM_M, 0); |
|---|
| 261 | 250 | |
|---|
| 262 | | - /* |
|---|
| 263 | | - * The rtc alarm status(BIT(6)) must be cleared after alarm 1s or |
|---|
| 264 | | - * after the alarm is disabled. |
|---|
| 265 | | - */ |
|---|
| 266 | | - ret = regmap_write(rk808->regmap, rk808_rtc->creg->status_reg, |
|---|
| 267 | | - RTC_ALARM_STATUS); |
|---|
| 268 | 251 | return ret; |
|---|
| 269 | 252 | } |
|---|
| 270 | 253 | |
|---|
| .. | .. |
|---|
| 292 | 275 | dev_err(dev, "Failed to stop alarm: %d\n", ret); |
|---|
| 293 | 276 | return ret; |
|---|
| 294 | 277 | } |
|---|
| 295 | | - dev_dbg(dev, "alrm set RTC date/time %4d-%02d-%02d(%d) %02d:%02d:%02d\n", |
|---|
| 296 | | - 1900 + alrm->time.tm_year, alrm->time.tm_mon + 1, |
|---|
| 297 | | - alrm->time.tm_mday, alrm->time.tm_wday, alrm->time.tm_hour, |
|---|
| 298 | | - alrm->time.tm_min, alrm->time.tm_sec); |
|---|
| 278 | + dev_dbg(dev, "alrm set RTC date/time %ptRd(%d) %ptRt\n", |
|---|
| 279 | + &alrm->time, alrm->time.tm_wday, &alrm->time); |
|---|
| 299 | 280 | |
|---|
| 300 | 281 | if (rk808_rtc->flag & RTC_NEED_TRANSITIONS) |
|---|
| 301 | 282 | gregorian_to_rockchip(&alrm->time); |
|---|
| .. | .. |
|---|
| 378 | 359 | /* Turn off the alarm if it should not be a wake source. */ |
|---|
| 379 | 360 | static int rk808_rtc_suspend(struct device *dev) |
|---|
| 380 | 361 | { |
|---|
| 381 | | - struct platform_device *pdev = to_platform_device(dev); |
|---|
| 382 | | - struct rk808_rtc *rk808_rtc = dev_get_drvdata(&pdev->dev); |
|---|
| 362 | + struct rk808_rtc *rk808_rtc = dev_get_drvdata(dev); |
|---|
| 383 | 363 | |
|---|
| 384 | 364 | if (device_may_wakeup(dev)) |
|---|
| 385 | 365 | enable_irq_wake(rk808_rtc->irq); |
|---|
| .. | .. |
|---|
| 392 | 372 | */ |
|---|
| 393 | 373 | static int rk808_rtc_resume(struct device *dev) |
|---|
| 394 | 374 | { |
|---|
| 395 | | - struct platform_device *pdev = to_platform_device(dev); |
|---|
| 396 | | - struct rk808_rtc *rk808_rtc = dev_get_drvdata(&pdev->dev); |
|---|
| 375 | + struct rk808_rtc *rk808_rtc = dev_get_drvdata(dev); |
|---|
| 397 | 376 | |
|---|
| 398 | 377 | if (device_may_wakeup(dev)) |
|---|
| 399 | 378 | disable_irq_wake(rk808_rtc->irq); |
|---|
| .. | .. |
|---|
| 484 | 463 | if (ret) { |
|---|
| 485 | 464 | dev_err(&pdev->dev, |
|---|
| 486 | 465 | "Failed to write RTC status: %d\n", ret); |
|---|
| 487 | | - return ret; |
|---|
| 466 | + return ret; |
|---|
| 488 | 467 | } |
|---|
| 489 | 468 | |
|---|
| 490 | 469 | device_init_wakeup(&pdev->dev, 1); |
|---|
| .. | .. |
|---|
| 496 | 475 | rk808_rtc->rtc->ops = &rk808_rtc_ops; |
|---|
| 497 | 476 | |
|---|
| 498 | 477 | rk808_rtc->irq = platform_get_irq(pdev, 0); |
|---|
| 499 | | - if (rk808_rtc->irq < 0) { |
|---|
| 500 | | - if (rk808_rtc->irq != -EPROBE_DEFER) |
|---|
| 501 | | - dev_err(&pdev->dev, "Wake up is not possible as irq = %d\n", |
|---|
| 502 | | - rk808_rtc->irq); |
|---|
| 478 | + if (rk808_rtc->irq < 0) |
|---|
| 503 | 479 | return rk808_rtc->irq; |
|---|
| 504 | | - } |
|---|
| 505 | 480 | |
|---|
| 506 | 481 | /* request alarm irq of rk808 */ |
|---|
| 507 | 482 | ret = devm_request_threaded_irq(&pdev->dev, rk808_rtc->irq, NULL, |
|---|