forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 95099d4622f8cb224d94e314c7a8e0df60b13f87
kernel/drivers/rtc/rtc-pm8xxx.c
....@@ -1,13 +1,5 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /* Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
2
- *
3
- * This program is free software; you can redistribute it and/or modify
4
- * it under the terms of the GNU General Public License version 2 and
5
- * only version 2 as published by the Free Software Foundation.
6
- *
7
- * This program is distributed in the hope that it will be useful,
8
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
- * GNU General Public License for more details.
113 */
124 #include <linux/of.h>
135 #include <linux/module.h>
....@@ -57,7 +49,7 @@
5749 * @regmap: regmap used to access RTC registers
5850 * @allow_set_time: indicates whether writing to the RTC is allowed
5951 * @rtc_alarm_irq: rtc alarm irq number.
60
- * @ctrl_reg: rtc control register.
52
+ * @regs: rtc registers description.
6153 * @rtc_dev: device structure.
6254 * @ctrl_reg_lock: spinlock protecting access to ctrl_reg.
6355 */
....@@ -92,7 +84,7 @@
9284 if (!rtc_dd->allow_set_time)
9385 return -EACCES;
9486
95
- rtc_tm_to_time(tm, &secs);
87
+ secs = rtc_tm_to_time64(tm);
9688
9789 dev_dbg(dev, "Seconds value to be written to RTC = %lu\n", secs);
9890
....@@ -216,11 +208,9 @@
216208 secs = value[0] | (value[1] << 8) | (value[2] << 16) |
217209 ((unsigned long)value[3] << 24);
218210
219
- rtc_time_to_tm(secs, tm);
211
+ rtc_time64_to_tm(secs, tm);
220212
221
- dev_dbg(dev, "secs = %lu, h:m:s == %d:%d:%d, d/m/y = %d/%d/%d\n",
222
- secs, tm->tm_hour, tm->tm_min, tm->tm_sec,
223
- tm->tm_mday, tm->tm_mon, tm->tm_year);
213
+ dev_dbg(dev, "secs = %lu, h:m:s == %ptRt, y-m-d = %ptRdr\n", secs, tm, tm);
224214
225215 return 0;
226216 }
....@@ -234,7 +224,7 @@
234224 struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev);
235225 const struct pm8xxx_rtc_regs *regs = rtc_dd->regs;
236226
237
- rtc_tm_to_time(&alarm->time, &secs);
227
+ secs = rtc_tm_to_time64(&alarm->time);
238228
239229 for (i = 0; i < NUM_8_BIT_RTC_REGS; i++) {
240230 value[i] = secs & 0xFF;
....@@ -265,10 +255,8 @@
265255 goto rtc_rw_fail;
266256 }
267257
268
- dev_dbg(dev, "Alarm Set for h:r:s=%d:%d:%d, d/m/y=%d/%d/%d\n",
269
- alarm->time.tm_hour, alarm->time.tm_min,
270
- alarm->time.tm_sec, alarm->time.tm_mday,
271
- alarm->time.tm_mon, alarm->time.tm_year);
258
+ dev_dbg(dev, "Alarm Set for h:m:s=%ptRt, y-m-d=%ptRdr\n",
259
+ &alarm->time, &alarm->time);
272260 rtc_rw_fail:
273261 spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags);
274262 return rc;
....@@ -292,18 +280,10 @@
292280 secs = value[0] | (value[1] << 8) | (value[2] << 16) |
293281 ((unsigned long)value[3] << 24);
294282
295
- rtc_time_to_tm(secs, &alarm->time);
283
+ rtc_time64_to_tm(secs, &alarm->time);
296284
297
- rc = rtc_valid_tm(&alarm->time);
298
- if (rc < 0) {
299
- dev_err(dev, "Invalid alarm time read from RTC\n");
300
- return rc;
301
- }
302
-
303
- dev_dbg(dev, "Alarm set for - h:r:s=%d:%d:%d, d/m/y=%d/%d/%d\n",
304
- alarm->time.tm_hour, alarm->time.tm_min,
305
- alarm->time.tm_sec, alarm->time.tm_mday,
306
- alarm->time.tm_mon, alarm->time.tm_year);
285
+ dev_dbg(dev, "Alarm set for - h:m:s=%ptRt, y-m-d=%ptRdr\n",
286
+ &alarm->time, &alarm->time);
307287
308288 return 0;
309289 }
....@@ -315,6 +295,7 @@
315295 struct pm8xxx_rtc *rtc_dd = dev_get_drvdata(dev);
316296 const struct pm8xxx_rtc_regs *regs = rtc_dd->regs;
317297 unsigned int ctrl_reg;
298
+ u8 value[NUM_8_BIT_RTC_REGS] = {0};
318299
319300 spin_lock_irqsave(&rtc_dd->ctrl_reg_lock, irq_flags);
320301
....@@ -331,6 +312,16 @@
331312 if (rc) {
332313 dev_err(dev, "Write to RTC control register failed\n");
333314 goto rtc_rw_fail;
315
+ }
316
+
317
+ /* Clear Alarm register */
318
+ if (!enable) {
319
+ rc = regmap_bulk_write(rtc_dd->regmap, regs->alarm_rw, value,
320
+ sizeof(value));
321
+ if (rc) {
322
+ dev_err(dev, "Clear RTC ALARM register failed\n");
323
+ goto rtc_rw_fail;
324
+ }
334325 }
335326
336327 rtc_rw_fail:
....@@ -482,10 +473,8 @@
482473 }
483474
484475 rtc_dd->rtc_alarm_irq = platform_get_irq(pdev, 0);
485
- if (rtc_dd->rtc_alarm_irq < 0) {
486
- dev_err(&pdev->dev, "Alarm IRQ resource absent!\n");
476
+ if (rtc_dd->rtc_alarm_irq < 0)
487477 return -ENXIO;
488
- }
489478
490479 rtc_dd->allow_set_time = of_property_read_bool(pdev->dev.of_node,
491480 "allow-set-time");
....@@ -502,13 +491,12 @@
502491 device_init_wakeup(&pdev->dev, 1);
503492
504493 /* Register the RTC device */
505
- rtc_dd->rtc = devm_rtc_device_register(&pdev->dev, "pm8xxx_rtc",
506
- &pm8xxx_rtc_ops, THIS_MODULE);
507
- if (IS_ERR(rtc_dd->rtc)) {
508
- dev_err(&pdev->dev, "%s: RTC registration failed (%ld)\n",
509
- __func__, PTR_ERR(rtc_dd->rtc));
494
+ rtc_dd->rtc = devm_rtc_allocate_device(&pdev->dev);
495
+ if (IS_ERR(rtc_dd->rtc))
510496 return PTR_ERR(rtc_dd->rtc);
511
- }
497
+
498
+ rtc_dd->rtc->ops = &pm8xxx_rtc_ops;
499
+ rtc_dd->rtc->range_max = U32_MAX;
512500
513501 /* Request the alarm IRQ */
514502 rc = devm_request_any_context_irq(&pdev->dev, rtc_dd->rtc_alarm_irq,
....@@ -520,9 +508,7 @@
520508 return rc;
521509 }
522510
523
- dev_dbg(&pdev->dev, "Probe success !!\n");
524
-
525
- return 0;
511
+ return rtc_register_device(rtc_dd->rtc);
526512 }
527513
528514 #ifdef CONFIG_PM_SLEEP