Commit 8e4ff713 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'rtc-5.2' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux

Pull RTC updates from Alexandre Belloni:
 "A huge series from me this cycle. I went through many drivers to set
  the date and time range supported by the RTC which helps solving HW
  limitation when the time comes (as early as next year for some). This
  time, I focused on drivers using .set_mms and .set_mmss64, allowing me
  to remove those callbacks. About a third of the patches got reviews, I
  actually own the RTCs and I tested another third and the remaining one
  are unlikely to cause any issues.

  Other than that, a single new driver and the usual fixes here and there.

  Summary:

  Subsystem:

   - set_mmss and set_mmss64 rtc_ops removal

   - Fix timestamp value for RTC_TIMESTAMP_BEGIN_1900

   - Use SPDX identifier for the core

   - validate upper bound of tm->tm_year

  New driver:

   - Aspeed BMC SoC RTC

  Drivers:

   - abx80x: use rtc_add_group

   - ds3232: nvram support

   - pcf85063: add alarm, nvram, offset correction and microcrystal
     rv8263 support

   - x1205: add of_match_table

   - Use set_time instead of set_mms/set_mmss64 for: ab3100, coh901331,
     digicolor, ds1672, ds2404, ep93xx, imxdi, jz4740, lpc32xx, mc13xxx,
     mxc, pcap, stmp3xxx, test, wm831x, xgene.

   - Set RTC range for: ab3100, at91sam9, coh901331, da9063, digicolor,
     dm355evm, ds1672, ds2404, ep39xx, goldfish, imxdi, jz4740, lpc32xx,
     mc13xxx, mv, mxc, omap, pcap, pcf85063, pcf85363, ps3, sh,
     stmp3xxx, sun4v, tegra, wm831x, xgene.

   - Switch to rtc_time64_to_tm/rtc_tm_to_time64 for the driver that
     properly set the RTC range.

   - Use dev_get_drvdata instead of multiple indirections"

* tag 'rtc-5.2' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux: (177 commits)
  rtc: snvs: Use __maybe_unused instead of #if CONFIG_PM_SLEEP
  rtc: imxdi: remove unused variable
  rtc: drop set_mms and set_mmss64
  rtc: pcap: convert to SPDX identifier
  rtc: pcap: use .set_time
  rtc: pcap: switch to rtc_time64_to_tm/rtc_tm_to_time64
  rtc: pcap: set range
  rtc: digicolor: convert to SPDX identifier
  rtc: digicolor: use .set_time
  rtc: digicolor: set range
  rtc: digicolor: fix possible race condition
  rtc: jz4740: convert to SPDX identifier
  rtc: jz4740: rework invalid time detection
  rtc: jz4740: use dev_pm_set_wake_irq() to simplify code
  rtc: jz4740: use .set_time
  rtc: jz4740: remove useless check
  rtc: jz4740: switch to rtc_time64_to_tm/rtc_tm_to_time64
  rtc: jz4740: set range
  rtc: 88pm860x: prevent use-after-free on device remove
  rtc: Use dev_get_drvdata()
  ...
parents 45182e4e dacb6a40
* NXP PCF85063 Real Time Clock * NXP PCF85063 Real Time Clock
Required properties: Required properties:
- compatible: Should contain "nxp,pcf85063". - compatible: Should one of contain:
"nxp,pcf85063",
"nxp,pcf85063a",
"nxp,pcf85063tp",
"microcrystal,rv8263"
- reg: I2C address for chip. - reg: I2C address for chip.
Optional property: Optional property:
......
ASPEED BMC RTC
==============
Required properties:
- compatible: should be one of the following
* aspeed,ast2400-rtc for the ast2400
* aspeed,ast2500-rtc for the ast2500
* aspeed,ast2600-rtc for the ast2600
- reg: physical base address of the controller and length of memory mapped
region
- interrupts: The interrupt number
Example:
rtc@1e781000 {
compatible = "aspeed,ast2400-rtc";
reg = <0x1e781000 0x18>;
interrupts = <22>;
status = "disabled";
};
...@@ -69,3 +69,4 @@ ricoh,rv5c386 I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC ...@@ -69,3 +69,4 @@ ricoh,rv5c386 I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
ricoh,rv5c387a I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC ricoh,rv5c387a I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
sii,s35390a 2-wire CMOS real-time clock sii,s35390a 2-wire CMOS real-time clock
whwave,sd3078 I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC whwave,sd3078 I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
xircom,x1205 Xircom X1205 I2C RTC
...@@ -439,6 +439,7 @@ config RTC_DRV_PCF8523 ...@@ -439,6 +439,7 @@ config RTC_DRV_PCF8523
config RTC_DRV_PCF85063 config RTC_DRV_PCF85063
tristate "NXP PCF85063" tristate "NXP PCF85063"
select REGMAP_I2C
help help
If you say yes here you get support for the PCF85063 RTC chip If you say yes here you get support for the PCF85063 RTC chip
...@@ -447,7 +448,6 @@ config RTC_DRV_PCF85063 ...@@ -447,7 +448,6 @@ config RTC_DRV_PCF85063
config RTC_DRV_PCF85363 config RTC_DRV_PCF85363
tristate "NXP PCF85363" tristate "NXP PCF85363"
depends on I2C
select REGMAP_I2C select REGMAP_I2C
help help
If you say yes here you get support for the PCF85363 RTC chip. If you say yes here you get support for the PCF85363 RTC chip.
...@@ -602,7 +602,6 @@ config RTC_DRV_FM3130 ...@@ -602,7 +602,6 @@ config RTC_DRV_FM3130
config RTC_DRV_RX8010 config RTC_DRV_RX8010
tristate "Epson RX8010SJ" tristate "Epson RX8010SJ"
depends on I2C
help help
If you say yes here you get support for the Epson RX8010SJ RTC If you say yes here you get support for the Epson RX8010SJ RTC
chip. chip.
...@@ -1432,7 +1431,7 @@ config RTC_DRV_AT91RM9200 ...@@ -1432,7 +1431,7 @@ config RTC_DRV_AT91RM9200
config RTC_DRV_AT91SAM9 config RTC_DRV_AT91SAM9
tristate "AT91SAM9 RTT as RTC" tristate "AT91SAM9 RTT as RTC"
depends on ARCH_AT91 || COMPILE_TEST depends on ARCH_AT91 || COMPILE_TEST
depends on HAS_IOMEM depends on OF && HAS_IOMEM
select MFD_SYSCON select MFD_SYSCON
help help
Some AT91SAM9 SoCs provide an RTT (Real Time Timer) block which Some AT91SAM9 SoCs provide an RTT (Real Time Timer) block which
...@@ -1841,6 +1840,17 @@ config RTC_DRV_RTD119X ...@@ -1841,6 +1840,17 @@ config RTC_DRV_RTD119X
If you say yes here, you get support for the RTD1295 SoC If you say yes here, you get support for the RTD1295 SoC
Real Time Clock. Real Time Clock.
config RTC_DRV_ASPEED
tristate "ASPEED RTC"
depends on OF
depends on ARCH_ASPEED || COMPILE_TEST
help
If you say yes here you get support for the ASPEED BMC SoC real time
clocks.
This driver can also be built as a module, if so, the module
will be called "rtc-aspeed".
comment "HID Sensor RTC drivers" comment "HID Sensor RTC drivers"
config RTC_DRV_HID_SENSOR_TIME config RTC_DRV_HID_SENSOR_TIME
...@@ -1857,7 +1867,8 @@ config RTC_DRV_HID_SENSOR_TIME ...@@ -1857,7 +1867,8 @@ config RTC_DRV_HID_SENSOR_TIME
config RTC_DRV_GOLDFISH config RTC_DRV_GOLDFISH
tristate "Goldfish Real Time Clock" tristate "Goldfish Real Time Clock"
depends on MIPS && (GOLDFISH || COMPILE_TEST) depends on OF && HAS_IOMEM
depends on GOLDFISH || COMPILE_TEST
help help
Say yes to enable RTC driver for the Goldfish based virtual platform. Say yes to enable RTC driver for the Goldfish based virtual platform.
......
...@@ -34,6 +34,7 @@ obj-$(CONFIG_RTC_DRV_AC100) += rtc-ac100.o ...@@ -34,6 +34,7 @@ obj-$(CONFIG_RTC_DRV_AC100) += rtc-ac100.o
obj-$(CONFIG_RTC_DRV_ARMADA38X) += rtc-armada38x.o obj-$(CONFIG_RTC_DRV_ARMADA38X) += rtc-armada38x.o
obj-$(CONFIG_RTC_DRV_AS3722) += rtc-as3722.o obj-$(CONFIG_RTC_DRV_AS3722) += rtc-as3722.o
obj-$(CONFIG_RTC_DRV_ASM9260) += rtc-asm9260.o obj-$(CONFIG_RTC_DRV_ASM9260) += rtc-asm9260.o
obj-$(CONFIG_RTC_DRV_ASPEED) += rtc-aspeed.o
obj-$(CONFIG_RTC_DRV_AT91RM9200)+= rtc-at91rm9200.o obj-$(CONFIG_RTC_DRV_AT91RM9200)+= rtc-at91rm9200.o
obj-$(CONFIG_RTC_DRV_AT91SAM9) += rtc-at91sam9.o obj-$(CONFIG_RTC_DRV_AT91SAM9) += rtc-at91sam9.o
obj-$(CONFIG_RTC_DRV_AU1XXX) += rtc-au1xxx.o obj-$(CONFIG_RTC_DRV_AU1XXX) += rtc-au1xxx.o
......
// SPDX-License-Identifier: GPL-2.0
/* /*
* RTC subsystem, base class * RTC subsystem, base class
* *
...@@ -5,11 +6,7 @@ ...@@ -5,11 +6,7 @@
* Author: Alessandro Zummo <a.zummo@towertech.it> * Author: Alessandro Zummo <a.zummo@towertech.it>
* *
* class skeleton from drivers/hwmon/hwmon.c * class skeleton from drivers/hwmon/hwmon.c
* */
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
...@@ -23,13 +20,13 @@ ...@@ -23,13 +20,13 @@
#include "rtc-core.h" #include "rtc-core.h"
static DEFINE_IDA(rtc_ida); static DEFINE_IDA(rtc_ida);
struct class *rtc_class; struct class *rtc_class;
static void rtc_device_release(struct device *dev) static void rtc_device_release(struct device *dev)
{ {
struct rtc_device *rtc = to_rtc_device(dev); struct rtc_device *rtc = to_rtc_device(dev);
ida_simple_remove(&rtc_ida, rtc->id); ida_simple_remove(&rtc_ida, rtc->id);
kfree(rtc); kfree(rtc);
} }
...@@ -47,7 +44,6 @@ int rtc_hctosys_ret = -ENODEV; ...@@ -47,7 +44,6 @@ int rtc_hctosys_ret = -ENODEV;
static struct timespec64 old_rtc, old_system, old_delta; static struct timespec64 old_rtc, old_system, old_delta;
static int rtc_suspend(struct device *dev) static int rtc_suspend(struct device *dev)
{ {
struct rtc_device *rtc = to_rtc_device(dev); struct rtc_device *rtc = to_rtc_device(dev);
...@@ -71,7 +67,6 @@ static int rtc_suspend(struct device *dev) ...@@ -71,7 +67,6 @@ static int rtc_suspend(struct device *dev)
ktime_get_real_ts64(&old_system); ktime_get_real_ts64(&old_system);
old_rtc.tv_sec = rtc_tm_to_time64(&tm); old_rtc.tv_sec = rtc_tm_to_time64(&tm);
/* /*
* To avoid drift caused by repeated suspend/resumes, * To avoid drift caused by repeated suspend/resumes,
* which each can add ~1 second drift error, * which each can add ~1 second drift error,
...@@ -83,7 +78,7 @@ static int rtc_suspend(struct device *dev) ...@@ -83,7 +78,7 @@ static int rtc_suspend(struct device *dev)
if (delta_delta.tv_sec < -2 || delta_delta.tv_sec >= 2) { if (delta_delta.tv_sec < -2 || delta_delta.tv_sec >= 2) {
/* /*
* if delta_delta is too large, assume time correction * if delta_delta is too large, assume time correction
* has occured and set old_delta to the current delta. * has occurred and set old_delta to the current delta.
*/ */
old_delta = delta; old_delta = delta;
} else { } else {
...@@ -136,7 +131,7 @@ static int rtc_resume(struct device *dev) ...@@ -136,7 +131,7 @@ static int rtc_resume(struct device *dev)
* to keep things accurate. * to keep things accurate.
*/ */
sleep_time = timespec64_sub(sleep_time, sleep_time = timespec64_sub(sleep_time,
timespec64_sub(new_system, old_system)); timespec64_sub(new_system, old_system));
if (sleep_time.tv_sec >= 0) if (sleep_time.tv_sec >= 0)
timekeeping_inject_sleeptime64(&sleep_time); timekeeping_inject_sleeptime64(&sleep_time);
...@@ -397,9 +392,9 @@ EXPORT_SYMBOL_GPL(__rtc_register_device); ...@@ -397,9 +392,9 @@ EXPORT_SYMBOL_GPL(__rtc_register_device);
* rtc_register_device instead * rtc_register_device instead
*/ */
struct rtc_device *devm_rtc_device_register(struct device *dev, struct rtc_device *devm_rtc_device_register(struct device *dev,
const char *name, const char *name,
const struct rtc_class_ops *ops, const struct rtc_class_ops *ops,
struct module *owner) struct module *owner)
{ {
struct rtc_device *rtc; struct rtc_device *rtc;
int err; int err;
......
// SPDX-License-Identifier: GPL-2.0
/* /*
* RTC subsystem, dev interface * RTC subsystem, dev interface
* *
...@@ -5,11 +6,7 @@ ...@@ -5,11 +6,7 @@
* Author: Alessandro Zummo <a.zummo@towertech.it> * Author: Alessandro Zummo <a.zummo@towertech.it>
* *
* based on arch/arm/common/rtctime.c * based on arch/arm/common/rtctime.c
* */
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
...@@ -60,7 +57,7 @@ static void rtc_uie_task(struct work_struct *work) ...@@ -60,7 +57,7 @@ static void rtc_uie_task(struct work_struct *work)
} else if (rtc->oldsecs != tm.tm_sec) { } else if (rtc->oldsecs != tm.tm_sec) {
num = (tm.tm_sec + 60 - rtc->oldsecs) % 60; num = (tm.tm_sec + 60 - rtc->oldsecs) % 60;
rtc->oldsecs = tm.tm_sec; rtc->oldsecs = tm.tm_sec;
rtc->uie_timer.expires = jiffies + HZ - (HZ/10); rtc->uie_timer.expires = jiffies + HZ - (HZ / 10);
rtc->uie_timer_active = 1; rtc->uie_timer_active = 1;
rtc->uie_task_active = 0; rtc->uie_task_active = 0;
add_timer(&rtc->uie_timer); add_timer(&rtc->uie_timer);
...@@ -71,6 +68,7 @@ static void rtc_uie_task(struct work_struct *work) ...@@ -71,6 +68,7 @@ static void rtc_uie_task(struct work_struct *work)
if (num) if (num)
rtc_handle_legacy_irq(rtc, num, RTC_UF); rtc_handle_legacy_irq(rtc, num, RTC_UF);
} }
static void rtc_uie_timer(struct timer_list *t) static void rtc_uie_timer(struct timer_list *t)
{ {
struct rtc_device *rtc = from_timer(rtc, t, uie_timer); struct rtc_device *rtc = from_timer(rtc, t, uie_timer);
...@@ -202,14 +200,14 @@ static __poll_t rtc_dev_poll(struct file *file, poll_table *wait) ...@@ -202,14 +200,14 @@ static __poll_t rtc_dev_poll(struct file *file, poll_table *wait)
} }
static long rtc_dev_ioctl(struct file *file, static long rtc_dev_ioctl(struct file *file,
unsigned int cmd, unsigned long arg) unsigned int cmd, unsigned long arg)
{ {
int err = 0; int err = 0;
struct rtc_device *rtc = file->private_data; struct rtc_device *rtc = file->private_data;
const struct rtc_class_ops *ops = rtc->ops; const struct rtc_class_ops *ops = rtc->ops;
struct rtc_time tm; struct rtc_time tm;
struct rtc_wkalrm alarm; struct rtc_wkalrm alarm;
void __user *uarg = (void __user *) arg; void __user *uarg = (void __user *)arg;
err = mutex_lock_interruptible(&rtc->ops_lock); err = mutex_lock_interruptible(&rtc->ops_lock);
if (err) if (err)
...@@ -233,7 +231,7 @@ static long rtc_dev_ioctl(struct file *file, ...@@ -233,7 +231,7 @@ static long rtc_dev_ioctl(struct file *file,
case RTC_PIE_ON: case RTC_PIE_ON:
if (rtc->irq_freq > rtc->max_user_freq && if (rtc->irq_freq > rtc->max_user_freq &&
!capable(CAP_SYS_RESOURCE)) !capable(CAP_SYS_RESOURCE))
err = -EACCES; err = -EACCES;
break; break;
} }
...@@ -390,8 +388,9 @@ static long rtc_dev_ioctl(struct file *file, ...@@ -390,8 +388,9 @@ static long rtc_dev_ioctl(struct file *file,
err = ops->ioctl(rtc->dev.parent, cmd, arg); err = ops->ioctl(rtc->dev.parent, cmd, arg);
if (err == -ENOIOCTLCMD) if (err == -ENOIOCTLCMD)
err = -ENOTTY; err = -ENOTTY;
} else } else {
err = -ENOTTY; err = -ENOTTY;
}
break; break;
} }
...@@ -403,6 +402,7 @@ static long rtc_dev_ioctl(struct file *file, ...@@ -403,6 +402,7 @@ static long rtc_dev_ioctl(struct file *file,
static int rtc_dev_fasync(int fd, struct file *file, int on) static int rtc_dev_fasync(int fd, struct file *file, int on)
{ {
struct rtc_device *rtc = file->private_data; struct rtc_device *rtc = file->private_data;
return fasync_helper(fd, file, on, &rtc->async_queue); return fasync_helper(fd, file, on, &rtc->async_queue);
} }
......
// SPDX-License-Identifier: GPL-2.0
/* /*
* RTC subsystem, initialize system time on startup * RTC subsystem, initialize system time on startup
* *
* Copyright (C) 2005 Tower Technologies * Copyright (C) 2005 Tower Technologies
* Author: Alessandro Zummo <a.zummo@towertech.it> * Author: Alessandro Zummo <a.zummo@towertech.it>
* */
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
...@@ -33,7 +30,7 @@ static int __init rtc_hctosys(void) ...@@ -33,7 +30,7 @@ static int __init rtc_hctosys(void)
}; };
struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE); struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE);
if (rtc == NULL) { if (!rtc) {
pr_info("unable to open rtc device (%s)\n", pr_info("unable to open rtc device (%s)\n",
CONFIG_RTC_HCTOSYS_DEVICE); CONFIG_RTC_HCTOSYS_DEVICE);
goto err_open; goto err_open;
...@@ -44,7 +41,6 @@ static int __init rtc_hctosys(void) ...@@ -44,7 +41,6 @@ static int __init rtc_hctosys(void)
dev_err(rtc->dev.parent, dev_err(rtc->dev.parent,
"hctosys: unable to read the hardware clock\n"); "hctosys: unable to read the hardware clock\n");
goto err_read; goto err_read;
} }
tv64.tv_sec = rtc_tm_to_time64(&tm); tv64.tv_sec = rtc_tm_to_time64(&tm);
......
// SPDX-License-Identifier: GPL-2.0
/* /*
* RTC subsystem, interface functions * RTC subsystem, interface functions
* *
...@@ -5,11 +6,7 @@ ...@@ -5,11 +6,7 @@
* Author: Alessandro Zummo <a.zummo@towertech.it> * Author: Alessandro Zummo <a.zummo@towertech.it>
* *
* based on arch/arm/common/rtctime.c * based on arch/arm/common/rtctime.c
* */
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include <linux/rtc.h> #include <linux/rtc.h>
#include <linux/sched.h> #include <linux/sched.h>
...@@ -87,11 +84,12 @@ static int rtc_valid_range(struct rtc_device *rtc, struct rtc_time *tm) ...@@ -87,11 +84,12 @@ static int rtc_valid_range(struct rtc_device *rtc, struct rtc_time *tm)
static int __rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm) static int __rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm)
{ {
int err; int err;
if (!rtc->ops)
if (!rtc->ops) {
err = -ENODEV; err = -ENODEV;
else if (!rtc->ops->read_time) } else if (!rtc->ops->read_time) {
err = -EINVAL; err = -EINVAL;
else { } else {
memset(tm, 0, sizeof(struct rtc_time)); memset(tm, 0, sizeof(struct rtc_time));
err = rtc->ops->read_time(rtc->dev.parent, tm); err = rtc->ops->read_time(rtc->dev.parent, tm);
if (err < 0) { if (err < 0) {
...@@ -147,14 +145,7 @@ int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm) ...@@ -147,14 +145,7 @@ int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm)
err = -ENODEV; err = -ENODEV;
else if (rtc->ops->set_time) else if (rtc->ops->set_time)
err = rtc->ops->set_time(rtc->dev.parent, tm); err = rtc->ops->set_time(rtc->dev.parent, tm);
else if (rtc->ops->set_mmss64) { else
time64_t secs64 = rtc_tm_to_time64(tm);
err = rtc->ops->set_mmss64(rtc->dev.parent, secs64);
} else if (rtc->ops->set_mmss) {
time64_t secs64 = rtc_tm_to_time64(tm);
err = rtc->ops->set_mmss(rtc->dev.parent, secs64);
} else
err = -EINVAL; err = -EINVAL;
pm_stay_awake(rtc->dev.parent); pm_stay_awake(rtc->dev.parent);
...@@ -167,7 +158,8 @@ int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm) ...@@ -167,7 +158,8 @@ int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm)
} }
EXPORT_SYMBOL_GPL(rtc_set_time); EXPORT_SYMBOL_GPL(rtc_set_time);
static int rtc_read_alarm_internal(struct rtc_device *rtc, struct rtc_wkalrm *alarm) static int rtc_read_alarm_internal(struct rtc_device *rtc,
struct rtc_wkalrm *alarm)
{ {
int err; int err;
...@@ -175,11 +167,11 @@ static int rtc_read_alarm_internal(struct rtc_device *rtc, struct rtc_wkalrm *al ...@@ -175,11 +167,11 @@ static int rtc_read_alarm_internal(struct rtc_device *rtc, struct rtc_wkalrm *al
if (err) if (err)
return err; return err;
if (rtc->ops == NULL) if (!rtc->ops) {
err = -ENODEV; err = -ENODEV;
else if (!rtc->ops->read_alarm) } else if (!rtc->ops->read_alarm) {
err = -EINVAL; err = -EINVAL;
else { } else {
alarm->enabled = 0; alarm->enabled = 0;
alarm->pending = 0; alarm->pending = 0;
alarm->time.tm_sec = -1; alarm->time.tm_sec = -1;
...@@ -207,7 +199,7 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) ...@@ -207,7 +199,7 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
int first_time = 1; int first_time = 1;
time64_t t_now, t_alm; time64_t t_now, t_alm;
enum { none, day, month, year } missing = none; enum { none, day, month, year } missing = none;
unsigned days; unsigned int days;
/* The lower level RTC driver may return -1 in some fields, /* The lower level RTC driver may return -1 in some fields,
* creating invalid alarm->time values, for reasons like: * creating invalid alarm->time values, for reasons like:
...@@ -276,10 +268,10 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) ...@@ -276,10 +268,10 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
return err; return err;
/* note that tm_sec is a "don't care" value here: */ /* note that tm_sec is a "don't care" value here: */
} while ( before.tm_min != now.tm_min } while (before.tm_min != now.tm_min ||
|| before.tm_hour != now.tm_hour before.tm_hour != now.tm_hour ||
|| before.tm_mon != now.tm_mon before.tm_mon != now.tm_mon ||
|| before.tm_year != now.tm_year); before.tm_year != now.tm_year);
/* Fill in the missing alarm fields using the timestamp; we /* Fill in the missing alarm fields using the timestamp; we
* know there's at least one since alarm->time is invalid. * know there's at least one since alarm->time is invalid.
...@@ -296,7 +288,7 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) ...@@ -296,7 +288,7 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
alarm->time.tm_mday = now.tm_mday; alarm->time.tm_mday = now.tm_mday;
missing = day; missing = day;
} }
if ((unsigned)alarm->time.tm_mon >= 12) { if ((unsigned int)alarm->time.tm_mon >= 12) {
alarm->time.tm_mon = now.tm_mon; alarm->time.tm_mon = now.tm_mon;
if (missing == none) if (missing == none)
missing = month; missing = month;
...@@ -321,7 +313,6 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) ...@@ -321,7 +313,6 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
goto done; goto done;
switch (missing) { switch (missing) {
/* 24 hour rollover ... if it's now 10am Monday, an alarm that /* 24 hour rollover ... if it's now 10am Monday, an alarm that
* that will trigger at 5am will do so at 5am Tuesday, which * that will trigger at 5am will do so at 5am Tuesday, which
* could also be in the next month or year. This is a common * could also be in the next month or year. This is a common
...@@ -341,14 +332,14 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) ...@@ -341,14 +332,14 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
case month: case month:
dev_dbg(&rtc->dev, "alarm rollover: %s\n", "month"); dev_dbg(&rtc->dev, "alarm rollover: %s\n", "month");
do { do {
if (alarm->time.tm_mon < 11) if (alarm->time.tm_mon < 11) {
alarm->time.tm_mon++; alarm->time.tm_mon++;
else { } else {
alarm->time.tm_mon = 0; alarm->time.tm_mon = 0;
alarm->time.tm_year++; alarm->time.tm_year++;
} }
days = rtc_month_days(alarm->time.tm_mon, days = rtc_month_days(alarm->time.tm_mon,
alarm->time.tm_year); alarm->time.tm_year);
} while (days < alarm->time.tm_mday); } while (days < alarm->time.tm_mday);
break; break;
...@@ -357,8 +348,8 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) ...@@ -357,8 +348,8 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
dev_dbg(&rtc->dev, "alarm rollover: %s\n", "year"); dev_dbg(&rtc->dev, "alarm rollover: %s\n", "year");
do { do {
alarm->time.tm_year++; alarm->time.tm_year++;
} while (!is_leap_year(alarm->time.tm_year + 1900) } while (!is_leap_year(alarm->time.tm_year + 1900) &&
&& rtc_valid_tm(&alarm->time) != 0); rtc_valid_tm(&alarm->time) != 0);
break; break;
default: default:
...@@ -369,7 +360,8 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) ...@@ -369,7 +360,8 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
done: done:
if (err) if (err)
dev_warn(&rtc->dev, "invalid alarm value: %ptR\n", &alarm->time); dev_warn(&rtc->dev, "invalid alarm value: %ptR\n",
&alarm->time);
return err; return err;
} }
...@@ -381,11 +373,11 @@ int rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) ...@@ -381,11 +373,11 @@ int rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
err = mutex_lock_interruptible(&rtc->ops_lock); err = mutex_lock_interruptible(&rtc->ops_lock);
if (err) if (err)
return err; return err;
if (rtc->ops == NULL) if (!rtc->ops) {
err = -ENODEV; err = -ENODEV;
else if (!rtc->ops->read_alarm) } else if (!rtc->ops->read_alarm) {
err = -EINVAL; err = -EINVAL;
else { } else {
memset(alarm, 0, sizeof(struct rtc_wkalrm)); memset(alarm, 0, sizeof(struct rtc_wkalrm));
alarm->enabled = rtc->aie_timer.enabled; alarm->enabled = rtc->aie_timer.enabled;
alarm->time = rtc_ktime_to_tm(rtc->aie_timer.node.expires); alarm->time = rtc_ktime_to_tm(rtc->aie_timer.node.expires);
...@@ -494,7 +486,6 @@ int rtc_initialize_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) ...@@ -494,7 +486,6 @@ int rtc_initialize_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
/* Alarm has to be enabled & in the future for us to enqueue it */ /* Alarm has to be enabled & in the future for us to enqueue it */
if (alarm->enabled && (rtc_tm_to_ktime(now) < if (alarm->enabled && (rtc_tm_to_ktime(now) <
rtc->aie_timer.node.expires)) { rtc->aie_timer.node.expires)) {
rtc->aie_timer.enabled = 1; rtc->aie_timer.enabled = 1;
timerqueue_add(&rtc->timerqueue, &rtc->aie_timer.node); timerqueue_add(&rtc->timerqueue, &rtc->aie_timer.node);
trace_rtc_timer_enqueue(&rtc->aie_timer); trace_rtc_timer_enqueue(&rtc->aie_timer);
...@@ -506,7 +497,9 @@ EXPORT_SYMBOL_GPL(rtc_initialize_alarm); ...@@ -506,7 +497,9 @@ EXPORT_SYMBOL_GPL(rtc_initialize_alarm);
int rtc_alarm_irq_enable(struct rtc_device *rtc, unsigned int enabled) int rtc_alarm_irq_enable(struct rtc_device *rtc, unsigned int enabled)
{ {
int err = mutex_lock_interruptible(&rtc->ops_lock); int err;
err = mutex_lock_interruptible(&rtc->ops_lock);
if (err) if (err)
return err; return err;
...@@ -535,7 +528,9 @@ EXPORT_SYMBOL_GPL(rtc_alarm_irq_enable); ...@@ -535,7 +528,9 @@ EXPORT_SYMBOL_GPL(rtc_alarm_irq_enable);
int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled) int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled)
{ {
int err = mutex_lock_interruptible(&rtc->ops_lock); int err;
err = mutex_lock_interruptible(&rtc->ops_lock);
if (err) if (err)
return err; return err;
...@@ -564,27 +559,25 @@ int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled) ...@@ -564,27 +559,25 @@ int rtc_update_irq_enable(struct rtc_device *rtc, unsigned int enabled)
rtc->uie_rtctimer.node.expires = ktime_add(now, onesec); rtc->uie_rtctimer.node.expires = ktime_add(now, onesec);
rtc->uie_rtctimer.period = ktime_set(1, 0); rtc->uie_rtctimer.period = ktime_set(1, 0);
err = rtc_timer_enqueue(rtc, &rtc->uie_rtctimer); err = rtc_timer_enqueue(rtc, &rtc->uie_rtctimer);
} else } else {
rtc_timer_remove(rtc, &rtc->uie_rtctimer); rtc_timer_remove(rtc, &rtc->uie_rtctimer);
}
out: out:
mutex_unlock(&rtc->ops_lock); mutex_unlock(&rtc->ops_lock);
#ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL #ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL
/* /*
* Enable emulation if the driver did not provide * Enable emulation if the driver returned -EINVAL to signal that it has
* the update_irq_enable function pointer or if returned * been configured without interrupts or they are not available at the
* -EINVAL to signal that it has been configured without * moment.
* interrupts or that are not available at the moment.
*/ */
if (err == -EINVAL) if (err == -EINVAL)
err = rtc_dev_update_irq_enable_emul(rtc, enabled); err = rtc_dev_update_irq_enable_emul(rtc, enabled);
#endif #endif
return err; return err;
} }
EXPORT_SYMBOL_GPL(rtc_update_irq_enable); EXPORT_SYMBOL_GPL(rtc_update_irq_enable);
/** /**
* rtc_handle_legacy_irq - AIE, UIE and PIE event hook * rtc_handle_legacy_irq - AIE, UIE and PIE event hook
* @rtc: pointer to the rtc device * @rtc: pointer to the rtc device
...@@ -599,14 +592,13 @@ void rtc_handle_legacy_irq(struct rtc_device *rtc, int num, int mode) ...@@ -599,14 +592,13 @@ void rtc_handle_legacy_irq(struct rtc_device *rtc, int num, int mode)
/* mark one irq of the appropriate mode */ /* mark one irq of the appropriate mode */
spin_lock_irqsave(&rtc->irq_lock, flags); spin_lock_irqsave(&rtc->irq_lock, flags);
rtc->irq_data = (rtc->irq_data + (num << 8)) | (RTC_IRQF|mode); rtc->irq_data = (rtc->irq_data + (num << 8)) | (RTC_IRQF | mode);
spin_unlock_irqrestore(&rtc->irq_lock, flags); spin_unlock_irqrestore(&rtc->irq_lock, flags);
wake_up_interruptible(&rtc->irq_queue); wake_up_interruptible(&rtc->irq_queue);
kill_fasync(&rtc->async_queue, SIGIO, POLL_IN); kill_fasync(&rtc->async_queue, SIGIO, POLL_IN);
} }
/** /**
* rtc_aie_update_irq - AIE mode rtctimer hook * rtc_aie_update_irq - AIE mode rtctimer hook
* @rtc: pointer to the rtc_device * @rtc: pointer to the rtc_device
...@@ -618,7 +610,6 @@ void rtc_aie_update_irq(struct rtc_device *rtc) ...@@ -618,7 +610,6 @@ void rtc_aie_update_irq(struct rtc_device *rtc)
rtc_handle_legacy_irq(rtc, 1, RTC_AF); rtc_handle_legacy_irq(rtc, 1, RTC_AF);
} }
/** /**
* rtc_uie_update_irq - UIE mode rtctimer hook * rtc_uie_update_irq - UIE mode rtctimer hook
* @rtc: pointer to the rtc_device * @rtc: pointer to the rtc_device
...@@ -630,7 +621,6 @@ void rtc_uie_update_irq(struct rtc_device *rtc) ...@@ -630,7 +621,6 @@ void rtc_uie_update_irq(struct rtc_device *rtc)
rtc_handle_legacy_irq(rtc, 1, RTC_UF); rtc_handle_legacy_irq(rtc, 1, RTC_UF);
} }
/** /**
* rtc_pie_update_irq - PIE mode hrtimer hook * rtc_pie_update_irq - PIE mode hrtimer hook
* @timer: pointer to the pie mode hrtimer * @timer: pointer to the pie mode hrtimer
...@@ -644,6 +634,7 @@ enum hrtimer_restart rtc_pie_update_irq(struct hrtimer *timer) ...@@ -644,6 +634,7 @@ enum hrtimer_restart rtc_pie_update_irq(struct hrtimer *timer)
struct rtc_device *rtc; struct rtc_device *rtc;
ktime_t period; ktime_t period;
int count; int count;
rtc = container_of(timer, struct rtc_device, pie_timer); rtc = container_of(timer, struct rtc_device, pie_timer);
period = NSEC_PER_SEC / rtc->irq_freq; period = NSEC_PER_SEC / rtc->irq_freq;
...@@ -662,7 +653,7 @@ enum hrtimer_restart rtc_pie_update_irq(struct hrtimer *timer) ...@@ -662,7 +653,7 @@ enum hrtimer_restart rtc_pie_update_irq(struct hrtimer *timer)
* Context: any * Context: any
*/ */
void rtc_update_irq(struct rtc_device *rtc, void rtc_update_irq(struct rtc_device *rtc,
unsigned long num, unsigned long events) unsigned long num, unsigned long events)
{ {
if (IS_ERR_OR_NULL(rtc)) if (IS_ERR_OR_NULL(rtc))
return; return;
...@@ -811,6 +802,7 @@ static int rtc_timer_enqueue(struct rtc_device *rtc, struct rtc_timer *timer) ...@@ -811,6 +802,7 @@ static int rtc_timer_enqueue(struct rtc_device *rtc, struct rtc_timer *timer)
if (!next || ktime_before(timer->node.expires, next->expires)) { if (!next || ktime_before(timer->node.expires, next->expires)) {
struct rtc_wkalrm alarm; struct rtc_wkalrm alarm;
int err; int err;
alarm.time = rtc_ktime_to_tm(timer->node.expires); alarm.time = rtc_ktime_to_tm(timer->node.expires);
alarm.enabled = 1; alarm.enabled = 1;
err = __rtc_set_alarm(rtc, &alarm); err = __rtc_set_alarm(rtc, &alarm);
...@@ -851,12 +843,14 @@ static void rtc_alarm_disable(struct rtc_device *rtc) ...@@ -851,12 +843,14 @@ static void rtc_alarm_disable(struct rtc_device *rtc)
static void rtc_timer_remove(struct rtc_device *rtc, struct rtc_timer *timer) static void rtc_timer_remove(struct rtc_device *rtc, struct rtc_timer *timer)
{ {
struct timerqueue_node *next = timerqueue_getnext(&rtc->timerqueue); struct timerqueue_node *next = timerqueue_getnext(&rtc->timerqueue);
timerqueue_del(&rtc->timerqueue, &timer->node); timerqueue_del(&rtc->timerqueue, &timer->node);
trace_rtc_timer_dequeue(timer); trace_rtc_timer_dequeue(timer);
timer->enabled = 0; timer->enabled = 0;
if (next == &timer->node) { if (next == &timer->node) {
struct rtc_wkalrm alarm; struct rtc_wkalrm alarm;
int err; int err;
next = timerqueue_getnext(&rtc->timerqueue); next = timerqueue_getnext(&rtc->timerqueue);
if (!next) { if (!next) {
rtc_alarm_disable(rtc); rtc_alarm_disable(rtc);
...@@ -929,9 +923,9 @@ void rtc_timer_do_work(struct work_struct *work) ...@@ -929,9 +923,9 @@ void rtc_timer_do_work(struct work_struct *work)
alarm.enabled = 1; alarm.enabled = 1;
reprogram: reprogram:
err = __rtc_set_alarm(rtc, &alarm); err = __rtc_set_alarm(rtc, &alarm);
if (err == -ETIME) if (err == -ETIME) {
goto again; goto again;
else if (err) { } else if (err) {
if (retry-- > 0) if (retry-- > 0)
goto reprogram; goto reprogram;
...@@ -942,14 +936,14 @@ void rtc_timer_do_work(struct work_struct *work) ...@@ -942,14 +936,14 @@ void rtc_timer_do_work(struct work_struct *work)
dev_err(&rtc->dev, "__rtc_set_alarm: err=%d\n", err); dev_err(&rtc->dev, "__rtc_set_alarm: err=%d\n", err);
goto again; goto again;
} }
} else } else {
rtc_alarm_disable(rtc); rtc_alarm_disable(rtc);
}
pm_relax(rtc->dev.parent); pm_relax(rtc->dev.parent);
mutex_unlock(&rtc->ops_lock); mutex_unlock(&rtc->ops_lock);
} }
/* rtc_timer_init - Initializes an rtc_timer /* rtc_timer_init - Initializes an rtc_timer
* @timer: timer to be intiialized * @timer: timer to be intiialized
* @f: function pointer to be called when timer fires * @f: function pointer to be called when timer fires
...@@ -975,9 +969,10 @@ void rtc_timer_init(struct rtc_timer *timer, void (*f)(struct rtc_device *r), ...@@ -975,9 +969,10 @@ void rtc_timer_init(struct rtc_timer *timer, void (*f)(struct rtc_device *r),
* Kernel interface to set an rtc_timer * Kernel interface to set an rtc_timer
*/ */
int rtc_timer_start(struct rtc_device *rtc, struct rtc_timer *timer, int rtc_timer_start(struct rtc_device *rtc, struct rtc_timer *timer,
ktime_t expires, ktime_t period) ktime_t expires, ktime_t period)
{ {
int ret = 0; int ret = 0;
mutex_lock(&rtc->ops_lock); mutex_lock(&rtc->ops_lock);
if (timer->enabled) if (timer->enabled)
rtc_timer_remove(rtc, timer); rtc_timer_remove(rtc, timer);
......
// SPDX-License-Identifier: GPL-2.0
/* /*
* rtc and date/time utility functions * rtc and date/time utility functions
* *
...@@ -5,11 +6,7 @@ ...@@ -5,11 +6,7 @@
* Author: Alessandro Zummo <a.zummo@towertech.it> * Author: Alessandro Zummo <a.zummo@towertech.it>
* *
* based on arch/arm/common/rtctime.c and other bits * based on arch/arm/common/rtctime.c and other bits
* */
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include <linux/export.h> #include <linux/export.h>
#include <linux/rtc.h> #include <linux/rtc.h>
...@@ -25,7 +22,7 @@ static const unsigned short rtc_ydays[2][13] = { ...@@ -25,7 +22,7 @@ static const unsigned short rtc_ydays[2][13] = {
{ 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 } { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
}; };
#define LEAPS_THRU_END_OF(y) ((y)/4 - (y)/100 + (y)/400) #define LEAPS_THRU_END_OF(y) ((y) / 4 - (y) / 100 + (y) / 400)
/* /*
* The number of days in the month. * The number of days in the month.
...@@ -41,11 +38,10 @@ EXPORT_SYMBOL(rtc_month_days); ...@@ -41,11 +38,10 @@ EXPORT_SYMBOL(rtc_month_days);
*/ */
int rtc_year_days(unsigned int day, unsigned int month, unsigned int year) int rtc_year_days(unsigned int day, unsigned int month, unsigned int year)
{ {
return rtc_ydays[is_leap_year(year)][month] + day-1; return rtc_ydays[is_leap_year(year)][month] + day - 1;
} }
EXPORT_SYMBOL(rtc_year_days); EXPORT_SYMBOL(rtc_year_days);
/* /*
* rtc_time64_to_tm - Converts time64_t to rtc_time. * rtc_time64_to_tm - Converts time64_t to rtc_time.
* Convert seconds since 01-01-1970 00:00:00 to Gregorian date. * Convert seconds since 01-01-1970 00:00:00 to Gregorian date.
...@@ -97,13 +93,15 @@ EXPORT_SYMBOL(rtc_time64_to_tm); ...@@ -97,13 +93,15 @@ EXPORT_SYMBOL(rtc_time64_to_tm);
*/ */
int rtc_valid_tm(struct rtc_time *tm) int rtc_valid_tm(struct rtc_time *tm)
{ {
if (tm->tm_year < 70 if (tm->tm_year < 70 ||
|| ((unsigned)tm->tm_mon) >= 12 tm->tm_year > (INT_MAX - 1900) ||
|| tm->tm_mday < 1 ((unsigned int)tm->tm_mon) >= 12 ||
|| tm->tm_mday > rtc_month_days(tm->tm_mon, ((unsigned)tm->tm_year + 1900)) tm->tm_mday < 1 ||
|| ((unsigned)tm->tm_hour) >= 24 tm->tm_mday > rtc_month_days(tm->tm_mon,
|| ((unsigned)tm->tm_min) >= 60 ((unsigned int)tm->tm_year + 1900)) ||
|| ((unsigned)tm->tm_sec) >= 60) ((unsigned int)tm->tm_hour) >= 24 ||
((unsigned int)tm->tm_min) >= 60 ||
((unsigned int)tm->tm_sec) >= 60)
return -EINVAL; return -EINVAL;
return 0; return 0;
...@@ -116,7 +114,7 @@ EXPORT_SYMBOL(rtc_valid_tm); ...@@ -116,7 +114,7 @@ EXPORT_SYMBOL(rtc_valid_tm);
*/ */
time64_t rtc_tm_to_time64(struct rtc_time *tm) time64_t rtc_tm_to_time64(struct rtc_time *tm)
{ {
return mktime64(((unsigned)tm->tm_year + 1900), tm->tm_mon + 1, return mktime64(((unsigned int)tm->tm_year + 1900), tm->tm_mon + 1,
tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
} }
EXPORT_SYMBOL(rtc_tm_to_time64); EXPORT_SYMBOL(rtc_tm_to_time64);
......
// SPDX-License-Identifier: GPL-2.0
/* /*
* RTC subsystem, nvmem interface * RTC subsystem, nvmem interface
* *
* Copyright (C) 2017 Alexandre Belloni * Copyright (C) 2017 Alexandre Belloni
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/ */
#include <linux/err.h> #include <linux/err.h>
...@@ -46,7 +43,7 @@ static int rtc_nvram_register(struct rtc_device *rtc, ...@@ -46,7 +43,7 @@ static int rtc_nvram_register(struct rtc_device *rtc,
{ {
int err; int err;
rtc->nvram = kzalloc(sizeof(struct bin_attribute), GFP_KERNEL); rtc->nvram = kzalloc(sizeof(*rtc->nvram), GFP_KERNEL);
if (!rtc->nvram) if (!rtc->nvram)
return -ENOMEM; return -ENOMEM;
......
// SPDX-License-Identifier: GPL-2.0
/* /*
* RTC subsystem, proc interface * RTC subsystem, proc interface
* *
...@@ -5,11 +6,7 @@ ...@@ -5,11 +6,7 @@
* Author: Alessandro Zummo <a.zummo@towertech.it> * Author: Alessandro Zummo <a.zummo@towertech.it>
* *
* based on arch/arm/common/rtctime.c * based on arch/arm/common/rtctime.c
* */
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include <linux/module.h> #include <linux/module.h>
#include <linux/rtc.h> #include <linux/rtc.h>
...@@ -60,17 +57,17 @@ static int rtc_proc_show(struct seq_file *seq, void *offset) ...@@ -60,17 +57,17 @@ static int rtc_proc_show(struct seq_file *seq, void *offset)
seq_printf(seq, "alrm_time\t: %ptRt\n", &alrm.time); seq_printf(seq, "alrm_time\t: %ptRt\n", &alrm.time);
seq_printf(seq, "alrm_date\t: %ptRd\n", &alrm.time); seq_printf(seq, "alrm_date\t: %ptRd\n", &alrm.time);
seq_printf(seq, "alarm_IRQ\t: %s\n", seq_printf(seq, "alarm_IRQ\t: %s\n",
alrm.enabled ? "yes" : "no"); alrm.enabled ? "yes" : "no");
seq_printf(seq, "alrm_pending\t: %s\n", seq_printf(seq, "alrm_pending\t: %s\n",
alrm.pending ? "yes" : "no"); alrm.pending ? "yes" : "no");
seq_printf(seq, "update IRQ enabled\t: %s\n", seq_printf(seq, "update IRQ enabled\t: %s\n",
(rtc->uie_rtctimer.enabled) ? "yes" : "no"); (rtc->uie_rtctimer.enabled) ? "yes" : "no");
seq_printf(seq, "periodic IRQ enabled\t: %s\n", seq_printf(seq, "periodic IRQ enabled\t: %s\n",
(rtc->pie_enabled) ? "yes" : "no"); (rtc->pie_enabled) ? "yes" : "no");
seq_printf(seq, "periodic IRQ frequency\t: %d\n", seq_printf(seq, "periodic IRQ frequency\t: %d\n",
rtc->irq_freq); rtc->irq_freq);
seq_printf(seq, "max user IRQ frequency\t: %d\n", seq_printf(seq, "max user IRQ frequency\t: %d\n",
rtc->max_user_freq); rtc->max_user_freq);
} }
seq_printf(seq, "24hr\t\t: yes\n"); seq_printf(seq, "24hr\t\t: yes\n");
...@@ -85,7 +82,7 @@ void rtc_proc_add_device(struct rtc_device *rtc) ...@@ -85,7 +82,7 @@ void rtc_proc_add_device(struct rtc_device *rtc)
{ {
if (is_rtc_hctosys(rtc)) if (is_rtc_hctosys(rtc))
proc_create_single_data("driver/rtc", 0, NULL, rtc_proc_show, proc_create_single_data("driver/rtc", 0, NULL, rtc_proc_show,
rtc); rtc);
} }
void rtc_proc_del_device(struct rtc_device *rtc) void rtc_proc_del_device(struct rtc_device *rtc)
......
// SPDX-License-Identifier: GPL-2.0
/* /*
* Real Time Clock driver for Marvell 88PM80x PMIC * Real Time Clock driver for Marvell 88PM80x PMIC
* *
* Copyright (c) 2012 Marvell International Ltd. * Copyright (c) 2012 Marvell International Ltd.
* Wenzeng Chen<wzch@marvell.com> * Wenzeng Chen<wzch@marvell.com>
* Qiao Zhou <zhouqiao@marvell.com> * Qiao Zhou <zhouqiao@marvell.com>
*
* This file is subject to the terms and conditions of the GNU General
* Public License. See the file "COPYING" in the main directory of this
* archive for more details.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include <linux/kernel.h> #include <linux/kernel.h>
......
...@@ -421,7 +421,7 @@ static int pm860x_rtc_remove(struct platform_device *pdev) ...@@ -421,7 +421,7 @@ static int pm860x_rtc_remove(struct platform_device *pdev)
struct pm860x_rtc_info *info = platform_get_drvdata(pdev); struct pm860x_rtc_info *info = platform_get_drvdata(pdev);
#ifdef VRTC_CALIBRATION #ifdef VRTC_CALIBRATION
flush_scheduled_work(); cancel_delayed_work_sync(&info->calib_work);
/* disable measurement */ /* disable measurement */
pm860x_set_bits(info->i2c, PM8607_MEAS_EN2, MEAS2_VRTC, 0); pm860x_set_bits(info->i2c, PM8607_MEAS_EN2, MEAS2_VRTC, 0);
#endif /* VRTC_CALIBRATION */ #endif /* VRTC_CALIBRATION */
......
// SPDX-License-Identifier: GPL-2.0+
/* /*
* rtc-ab-b5ze-s3 - Driver for Abracon AB-RTCMC-32.768Khz-B5ZE-S3 * rtc-ab-b5ze-s3 - Driver for Abracon AB-RTCMC-32.768Khz-B5ZE-S3
* I2C RTC / Alarm chip * I2C RTC / Alarm chip
...@@ -10,19 +11,9 @@ ...@@ -10,19 +11,9 @@
* *
* This work is based on ISL12057 driver (drivers/rtc/rtc-isl12057.c). * This work is based on ISL12057 driver (drivers/rtc/rtc-isl12057.c).
* *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/ */
#include <linux/module.h> #include <linux/module.h>
#include <linux/mutex.h>
#include <linux/rtc.h> #include <linux/rtc.h>
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/bcd.h> #include <linux/bcd.h>
...@@ -128,7 +119,6 @@ ...@@ -128,7 +119,6 @@
struct abb5zes3_rtc_data { struct abb5zes3_rtc_data {
struct rtc_device *rtc; struct rtc_device *rtc;
struct regmap *regmap; struct regmap *regmap;
struct mutex lock;
int irq; int irq;
...@@ -138,8 +128,7 @@ struct abb5zes3_rtc_data { ...@@ -138,8 +128,7 @@ struct abb5zes3_rtc_data {
/* /*
* Try and match register bits w/ fixed null values to see whether we * Try and match register bits w/ fixed null values to see whether we
* are dealing with an ABB5ZES3. Note: this function is called early * are dealing with an ABB5ZES3.
* during init and hence does need mutex protection.
*/ */
static int abb5zes3_i2c_validate_chip(struct regmap *regmap) static int abb5zes3_i2c_validate_chip(struct regmap *regmap)
{ {
...@@ -230,14 +219,12 @@ static int _abb5zes3_rtc_read_time(struct device *dev, struct rtc_time *tm) ...@@ -230,14 +219,12 @@ static int _abb5zes3_rtc_read_time(struct device *dev, struct rtc_time *tm)
if (ret) { if (ret) {
dev_err(dev, "%s: reading RTC time failed (%d)\n", dev_err(dev, "%s: reading RTC time failed (%d)\n",
__func__, ret); __func__, ret);
goto err; return ret;
} }
/* If clock integrity is not guaranteed, do not return a time value */ /* If clock integrity is not guaranteed, do not return a time value */
if (regs[ABB5ZES3_REG_RTC_SC] & ABB5ZES3_REG_RTC_SC_OSC) { if (regs[ABB5ZES3_REG_RTC_SC] & ABB5ZES3_REG_RTC_SC_OSC)
ret = -ENODATA; return -ENODATA;
goto err;
}
tm->tm_sec = bcd2bin(regs[ABB5ZES3_REG_RTC_SC] & 0x7F); tm->tm_sec = bcd2bin(regs[ABB5ZES3_REG_RTC_SC] & 0x7F);
tm->tm_min = bcd2bin(regs[ABB5ZES3_REG_RTC_MN]); tm->tm_min = bcd2bin(regs[ABB5ZES3_REG_RTC_MN]);
...@@ -255,7 +242,6 @@ static int _abb5zes3_rtc_read_time(struct device *dev, struct rtc_time *tm) ...@@ -255,7 +242,6 @@ static int _abb5zes3_rtc_read_time(struct device *dev, struct rtc_time *tm)
tm->tm_mon = bcd2bin(regs[ABB5ZES3_REG_RTC_MO]) - 1; /* starts at 1 */ tm->tm_mon = bcd2bin(regs[ABB5ZES3_REG_RTC_MO]) - 1; /* starts at 1 */
tm->tm_year = bcd2bin(regs[ABB5ZES3_REG_RTC_YR]) + 100; tm->tm_year = bcd2bin(regs[ABB5ZES3_REG_RTC_YR]) + 100;
err:
return ret; return ret;
} }
...@@ -273,12 +259,9 @@ static int abb5zes3_rtc_set_time(struct device *dev, struct rtc_time *tm) ...@@ -273,12 +259,9 @@ static int abb5zes3_rtc_set_time(struct device *dev, struct rtc_time *tm)
regs[ABB5ZES3_REG_RTC_MO] = bin2bcd(tm->tm_mon + 1); regs[ABB5ZES3_REG_RTC_MO] = bin2bcd(tm->tm_mon + 1);
regs[ABB5ZES3_REG_RTC_YR] = bin2bcd(tm->tm_year - 100); regs[ABB5ZES3_REG_RTC_YR] = bin2bcd(tm->tm_year - 100);
mutex_lock(&data->lock);
ret = regmap_bulk_write(data->regmap, ABB5ZES3_REG_RTC_SC, ret = regmap_bulk_write(data->regmap, ABB5ZES3_REG_RTC_SC,
regs + ABB5ZES3_REG_RTC_SC, regs + ABB5ZES3_REG_RTC_SC,
ABB5ZES3_RTC_SEC_LEN); ABB5ZES3_RTC_SEC_LEN);
mutex_unlock(&data->lock);
return ret; return ret;
} }
...@@ -332,38 +315,35 @@ static int _abb5zes3_rtc_read_timer(struct device *dev, ...@@ -332,38 +315,35 @@ static int _abb5zes3_rtc_read_timer(struct device *dev,
if (ret) { if (ret) {
dev_err(dev, "%s: reading Timer A section failed (%d)\n", dev_err(dev, "%s: reading Timer A section failed (%d)\n",
__func__, ret); __func__, ret);
goto err; return ret;
} }
/* get current time ... */ /* get current time ... */
ret = _abb5zes3_rtc_read_time(dev, &rtc_tm); ret = _abb5zes3_rtc_read_time(dev, &rtc_tm);
if (ret) if (ret)
goto err; return ret;
/* ... convert to seconds ... */ /* ... convert to seconds ... */
ret = rtc_tm_to_time(&rtc_tm, &rtc_secs); rtc_secs = rtc_tm_to_time64(&rtc_tm);
if (ret)
goto err;
/* ... add remaining timer A time ... */ /* ... add remaining timer A time ... */
ret = sec_from_timer_a(&timer_secs, regs[1], regs[2]); ret = sec_from_timer_a(&timer_secs, regs[1], regs[2]);
if (ret) if (ret)
goto err; return ret;
/* ... and convert back. */ /* ... and convert back. */
rtc_time_to_tm(rtc_secs + timer_secs, alarm_tm); rtc_time64_to_tm(rtc_secs + timer_secs, alarm_tm);
ret = regmap_read(data->regmap, ABB5ZES3_REG_CTRL2, &reg); ret = regmap_read(data->regmap, ABB5ZES3_REG_CTRL2, &reg);
if (ret) { if (ret) {
dev_err(dev, "%s: reading ctrl reg failed (%d)\n", dev_err(dev, "%s: reading ctrl reg failed (%d)\n",
__func__, ret); __func__, ret);
goto err; return ret;
} }
alarm->enabled = !!(reg & ABB5ZES3_REG_CTRL2_WTAIE); alarm->enabled = !!(reg & ABB5ZES3_REG_CTRL2_WTAIE);
err: return 0;
return ret;
} }
/* Read alarm currently configured via a RTC alarm registers. */ /* Read alarm currently configured via a RTC alarm registers. */
...@@ -382,7 +362,7 @@ static int _abb5zes3_rtc_read_alarm(struct device *dev, ...@@ -382,7 +362,7 @@ static int _abb5zes3_rtc_read_alarm(struct device *dev,
if (ret) { if (ret) {
dev_err(dev, "%s: reading alarm section failed (%d)\n", dev_err(dev, "%s: reading alarm section failed (%d)\n",
__func__, ret); __func__, ret);
goto err; return ret;
} }
alarm_tm->tm_sec = 0; alarm_tm->tm_sec = 0;
...@@ -398,18 +378,13 @@ static int _abb5zes3_rtc_read_alarm(struct device *dev, ...@@ -398,18 +378,13 @@ static int _abb5zes3_rtc_read_alarm(struct device *dev,
*/ */
ret = _abb5zes3_rtc_read_time(dev, &rtc_tm); ret = _abb5zes3_rtc_read_time(dev, &rtc_tm);
if (ret) if (ret)
goto err; return ret;
alarm_tm->tm_year = rtc_tm.tm_year; alarm_tm->tm_year = rtc_tm.tm_year;
alarm_tm->tm_mon = rtc_tm.tm_mon; alarm_tm->tm_mon = rtc_tm.tm_mon;
ret = rtc_tm_to_time(&rtc_tm, &rtc_secs); rtc_secs = rtc_tm_to_time64(&rtc_tm);
if (ret) alarm_secs = rtc_tm_to_time64(alarm_tm);
goto err;
ret = rtc_tm_to_time(alarm_tm, &alarm_secs);
if (ret)
goto err;
if (alarm_secs < rtc_secs) { if (alarm_secs < rtc_secs) {
if (alarm_tm->tm_mon == 11) { if (alarm_tm->tm_mon == 11) {
...@@ -424,13 +399,12 @@ static int _abb5zes3_rtc_read_alarm(struct device *dev, ...@@ -424,13 +399,12 @@ static int _abb5zes3_rtc_read_alarm(struct device *dev,
if (ret) { if (ret) {
dev_err(dev, "%s: reading ctrl reg failed (%d)\n", dev_err(dev, "%s: reading ctrl reg failed (%d)\n",
__func__, ret); __func__, ret);
goto err; return ret;
} }
alarm->enabled = !!(reg & ABB5ZES3_REG_CTRL1_AIE); alarm->enabled = !!(reg & ABB5ZES3_REG_CTRL1_AIE);
err: return 0;
return ret;
} }
/* /*
...@@ -447,12 +421,10 @@ static int abb5zes3_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) ...@@ -447,12 +421,10 @@ static int abb5zes3_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
struct abb5zes3_rtc_data *data = dev_get_drvdata(dev); struct abb5zes3_rtc_data *data = dev_get_drvdata(dev);
int ret; int ret;
mutex_lock(&data->lock);
if (data->timer_alarm) if (data->timer_alarm)
ret = _abb5zes3_rtc_read_timer(dev, alarm); ret = _abb5zes3_rtc_read_timer(dev, alarm);
else else
ret = _abb5zes3_rtc_read_alarm(dev, alarm); ret = _abb5zes3_rtc_read_alarm(dev, alarm);
mutex_unlock(&data->lock);
return ret; return ret;
} }
...@@ -466,33 +438,25 @@ static int _abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) ...@@ -466,33 +438,25 @@ static int _abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
{ {
struct abb5zes3_rtc_data *data = dev_get_drvdata(dev); struct abb5zes3_rtc_data *data = dev_get_drvdata(dev);
struct rtc_time *alarm_tm = &alarm->time; struct rtc_time *alarm_tm = &alarm->time;
unsigned long rtc_secs, alarm_secs;
u8 regs[ABB5ZES3_ALRM_SEC_LEN]; u8 regs[ABB5ZES3_ALRM_SEC_LEN];
struct rtc_time rtc_tm; struct rtc_time rtc_tm;
int ret, enable = 1; int ret, enable = 1;
ret = _abb5zes3_rtc_read_time(dev, &rtc_tm); if (!alarm->enabled) {
if (ret)
goto err;
ret = rtc_tm_to_time(&rtc_tm, &rtc_secs);
if (ret)
goto err;
ret = rtc_tm_to_time(alarm_tm, &alarm_secs);
if (ret)
goto err;
/* If alarm time is before current time, disable the alarm */
if (!alarm->enabled || alarm_secs <= rtc_secs) {
enable = 0; enable = 0;
} else { } else {
unsigned long rtc_secs, alarm_secs;
/* /*
* Chip only support alarms up to one month in the future. Let's * Chip only support alarms up to one month in the future. Let's
* return an error if we get something after that limit. * return an error if we get something after that limit.
* Comparison is done by incrementing rtc_tm month field by one * Comparison is done by incrementing rtc_tm month field by one
* and checking alarm value is still below. * and checking alarm value is still below.
*/ */
ret = _abb5zes3_rtc_read_time(dev, &rtc_tm);
if (ret)
return ret;
if (rtc_tm.tm_mon == 11) { /* handle year wrapping */ if (rtc_tm.tm_mon == 11) { /* handle year wrapping */
rtc_tm.tm_mon = 0; rtc_tm.tm_mon = 0;
rtc_tm.tm_year += 1; rtc_tm.tm_year += 1;
...@@ -500,15 +464,13 @@ static int _abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) ...@@ -500,15 +464,13 @@ static int _abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
rtc_tm.tm_mon += 1; rtc_tm.tm_mon += 1;
} }
ret = rtc_tm_to_time(&rtc_tm, &rtc_secs); rtc_secs = rtc_tm_to_time64(&rtc_tm);
if (ret) alarm_secs = rtc_tm_to_time64(alarm_tm);
goto err;
if (alarm_secs > rtc_secs) { if (alarm_secs > rtc_secs) {
dev_err(dev, "%s: alarm maximum is one month in the " dev_err(dev, "%s: alarm maximum is one month in the future (%d)\n",
"future (%d)\n", __func__, ret); __func__, ret);
ret = -EINVAL; return -EINVAL;
goto err;
} }
} }
...@@ -526,17 +488,14 @@ static int _abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) ...@@ -526,17 +488,14 @@ static int _abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
if (ret < 0) { if (ret < 0) {
dev_err(dev, "%s: writing ALARM section failed (%d)\n", dev_err(dev, "%s: writing ALARM section failed (%d)\n",
__func__, ret); __func__, ret);
goto err; return ret;
} }
/* Record currently configured alarm is not a timer */ /* Record currently configured alarm is not a timer */
data->timer_alarm = 0; data->timer_alarm = 0;
/* Enable or disable alarm interrupt generation */ /* Enable or disable alarm interrupt generation */
ret = _abb5zes3_rtc_update_alarm(dev, enable); return _abb5zes3_rtc_update_alarm(dev, enable);
err:
return ret;
} }
/* /*
...@@ -557,7 +516,7 @@ static int _abb5zes3_rtc_set_timer(struct device *dev, struct rtc_wkalrm *alarm, ...@@ -557,7 +516,7 @@ static int _abb5zes3_rtc_set_timer(struct device *dev, struct rtc_wkalrm *alarm,
ABB5ZES3_TIMA_SEC_LEN); ABB5ZES3_TIMA_SEC_LEN);
if (ret < 0) { if (ret < 0) {
dev_err(dev, "%s: writing timer section failed\n", __func__); dev_err(dev, "%s: writing timer section failed\n", __func__);
goto err; return ret;
} }
/* Configure Timer A as a watchdog timer */ /* Configure Timer A as a watchdog timer */
...@@ -570,10 +529,7 @@ static int _abb5zes3_rtc_set_timer(struct device *dev, struct rtc_wkalrm *alarm, ...@@ -570,10 +529,7 @@ static int _abb5zes3_rtc_set_timer(struct device *dev, struct rtc_wkalrm *alarm,
data->timer_alarm = 1; data->timer_alarm = 1;
/* Enable or disable timer interrupt generation */ /* Enable or disable timer interrupt generation */
ret = _abb5zes3_rtc_update_timer(dev, alarm->enabled); return _abb5zes3_rtc_update_timer(dev, alarm->enabled);
err:
return ret;
} }
/* /*
...@@ -590,31 +546,25 @@ static int abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) ...@@ -590,31 +546,25 @@ static int abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
struct rtc_time rtc_tm; struct rtc_time rtc_tm;
int ret; int ret;
mutex_lock(&data->lock);
ret = _abb5zes3_rtc_read_time(dev, &rtc_tm); ret = _abb5zes3_rtc_read_time(dev, &rtc_tm);
if (ret) if (ret)
goto err; return ret;
ret = rtc_tm_to_time(&rtc_tm, &rtc_secs); rtc_secs = rtc_tm_to_time64(&rtc_tm);
if (ret) alarm_secs = rtc_tm_to_time64(alarm_tm);
goto err;
ret = rtc_tm_to_time(alarm_tm, &alarm_secs);
if (ret)
goto err;
/* Let's first disable both the alarm and the timer interrupts */ /* Let's first disable both the alarm and the timer interrupts */
ret = _abb5zes3_rtc_update_alarm(dev, false); ret = _abb5zes3_rtc_update_alarm(dev, false);
if (ret < 0) { if (ret < 0) {
dev_err(dev, "%s: unable to disable alarm (%d)\n", __func__, dev_err(dev, "%s: unable to disable alarm (%d)\n", __func__,
ret); ret);
goto err; return ret;
} }
ret = _abb5zes3_rtc_update_timer(dev, false); ret = _abb5zes3_rtc_update_timer(dev, false);
if (ret < 0) { if (ret < 0) {
dev_err(dev, "%s: unable to disable timer (%d)\n", __func__, dev_err(dev, "%s: unable to disable timer (%d)\n", __func__,
ret); ret);
goto err; return ret;
} }
data->timer_alarm = 0; data->timer_alarm = 0;
...@@ -629,9 +579,6 @@ static int abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) ...@@ -629,9 +579,6 @@ static int abb5zes3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
else else
ret = _abb5zes3_rtc_set_alarm(dev, alarm); ret = _abb5zes3_rtc_set_alarm(dev, alarm);
err:
mutex_unlock(&data->lock);
if (ret) if (ret)
dev_err(dev, "%s: unable to configure alarm (%d)\n", __func__, dev_err(dev, "%s: unable to configure alarm (%d)\n", __func__,
ret); ret);
...@@ -650,8 +597,7 @@ static inline int _abb5zes3_rtc_battery_low_irq_enable(struct regmap *regmap, ...@@ -650,8 +597,7 @@ static inline int _abb5zes3_rtc_battery_low_irq_enable(struct regmap *regmap,
/* /*
* Check current RTC status and enable/disable what needs to be. Return 0 if * Check current RTC status and enable/disable what needs to be. Return 0 if
* everything went ok and a negative value upon error. Note: this function * everything went ok and a negative value upon error.
* is called early during init and hence does need mutex protection.
*/ */
static int abb5zes3_rtc_check_setup(struct device *dev) static int abb5zes3_rtc_check_setup(struct device *dev)
{ {
...@@ -675,8 +621,9 @@ static int abb5zes3_rtc_check_setup(struct device *dev) ...@@ -675,8 +621,9 @@ static int abb5zes3_rtc_check_setup(struct device *dev)
ABB5ZES3_REG_TIM_CLK_COF1 | ABB5ZES3_REG_TIM_CLK_COF2 | ABB5ZES3_REG_TIM_CLK_COF1 | ABB5ZES3_REG_TIM_CLK_COF2 |
ABB5ZES3_REG_TIM_CLK_TBM | ABB5ZES3_REG_TIM_CLK_TAM); ABB5ZES3_REG_TIM_CLK_TBM | ABB5ZES3_REG_TIM_CLK_TAM);
ret = regmap_update_bits(regmap, ABB5ZES3_REG_TIM_CLK, mask, ret = regmap_update_bits(regmap, ABB5ZES3_REG_TIM_CLK, mask,
ABB5ZES3_REG_TIM_CLK_COF0 | ABB5ZES3_REG_TIM_CLK_COF1 | ABB5ZES3_REG_TIM_CLK_COF0 |
ABB5ZES3_REG_TIM_CLK_COF2); ABB5ZES3_REG_TIM_CLK_COF1 |
ABB5ZES3_REG_TIM_CLK_COF2);
if (ret < 0) { if (ret < 0) {
dev_err(dev, "%s: unable to initialize clkout register (%d)\n", dev_err(dev, "%s: unable to initialize clkout register (%d)\n",
__func__, ret); __func__, ret);
...@@ -729,9 +676,9 @@ static int abb5zes3_rtc_check_setup(struct device *dev) ...@@ -729,9 +676,9 @@ static int abb5zes3_rtc_check_setup(struct device *dev)
* switchover flag but not battery low flag. The latter is checked * switchover flag but not battery low flag. The latter is checked
* later below. * later below.
*/ */
mask = (ABB5ZES3_REG_CTRL3_PM0 | ABB5ZES3_REG_CTRL3_PM1 | mask = (ABB5ZES3_REG_CTRL3_PM0 | ABB5ZES3_REG_CTRL3_PM1 |
ABB5ZES3_REG_CTRL3_PM2 | ABB5ZES3_REG_CTRL3_BLIE | ABB5ZES3_REG_CTRL3_PM2 | ABB5ZES3_REG_CTRL3_BLIE |
ABB5ZES3_REG_CTRL3_BSIE| ABB5ZES3_REG_CTRL3_BSF); ABB5ZES3_REG_CTRL3_BSIE | ABB5ZES3_REG_CTRL3_BSF);
ret = regmap_update_bits(regmap, ABB5ZES3_REG_CTRL3, mask, 0); ret = regmap_update_bits(regmap, ABB5ZES3_REG_CTRL3, mask, 0);
if (ret < 0) { if (ret < 0) {
dev_err(dev, "%s: unable to initialize CTRL3 register (%d)\n", dev_err(dev, "%s: unable to initialize CTRL3 register (%d)\n",
...@@ -748,10 +695,8 @@ static int abb5zes3_rtc_check_setup(struct device *dev) ...@@ -748,10 +695,8 @@ static int abb5zes3_rtc_check_setup(struct device *dev)
} }
if (reg & ABB5ZES3_REG_RTC_SC_OSC) { if (reg & ABB5ZES3_REG_RTC_SC_OSC) {
dev_err(dev, "clock integrity not guaranteed. Osc. has stopped " dev_err(dev, "clock integrity not guaranteed. Osc. has stopped or has been interrupted.\n");
"or has been interrupted.\n"); dev_err(dev, "change battery (if not already done) and then set time to reset osc. failure flag.\n");
dev_err(dev, "change battery (if not already done) and "
"then set time to reset osc. failure flag.\n");
} }
/* /*
...@@ -769,13 +714,12 @@ static int abb5zes3_rtc_check_setup(struct device *dev) ...@@ -769,13 +714,12 @@ static int abb5zes3_rtc_check_setup(struct device *dev)
data->battery_low = reg & ABB5ZES3_REG_CTRL3_BLF; data->battery_low = reg & ABB5ZES3_REG_CTRL3_BLF;
if (data->battery_low) { if (data->battery_low) {
dev_err(dev, "RTC battery is low; please, consider " dev_err(dev, "RTC battery is low; please, consider changing it!\n");
"changing it!\n");
ret = _abb5zes3_rtc_battery_low_irq_enable(regmap, false); ret = _abb5zes3_rtc_battery_low_irq_enable(regmap, false);
if (ret) if (ret)
dev_err(dev, "%s: disabling battery low interrupt " dev_err(dev, "%s: disabling battery low interrupt generation failed (%d)\n",
"generation failed (%d)\n", __func__, ret); __func__, ret);
} }
return ret; return ret;
...@@ -788,12 +732,10 @@ static int abb5zes3_rtc_alarm_irq_enable(struct device *dev, ...@@ -788,12 +732,10 @@ static int abb5zes3_rtc_alarm_irq_enable(struct device *dev,
int ret = 0; int ret = 0;
if (rtc_data->irq) { if (rtc_data->irq) {
mutex_lock(&rtc_data->lock);
if (rtc_data->timer_alarm) if (rtc_data->timer_alarm)
ret = _abb5zes3_rtc_update_timer(dev, enable); ret = _abb5zes3_rtc_update_timer(dev, enable);
else else
ret = _abb5zes3_rtc_update_alarm(dev, enable); ret = _abb5zes3_rtc_update_alarm(dev, enable);
mutex_unlock(&rtc_data->lock);
} }
return ret; return ret;
...@@ -885,49 +827,44 @@ static int abb5zes3_probe(struct i2c_client *client, ...@@ -885,49 +827,44 @@ static int abb5zes3_probe(struct i2c_client *client,
if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C | if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C |
I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_BYTE_DATA |
I2C_FUNC_SMBUS_I2C_BLOCK)) { I2C_FUNC_SMBUS_I2C_BLOCK))
ret = -ENODEV; return -ENODEV;
goto err;
}
regmap = devm_regmap_init_i2c(client, &abb5zes3_rtc_regmap_config); regmap = devm_regmap_init_i2c(client, &abb5zes3_rtc_regmap_config);
if (IS_ERR(regmap)) { if (IS_ERR(regmap)) {
ret = PTR_ERR(regmap); ret = PTR_ERR(regmap);
dev_err(dev, "%s: regmap allocation failed: %d\n", dev_err(dev, "%s: regmap allocation failed: %d\n",
__func__, ret); __func__, ret);
goto err; return ret;
} }
ret = abb5zes3_i2c_validate_chip(regmap); ret = abb5zes3_i2c_validate_chip(regmap);
if (ret) if (ret)
goto err; return ret;
data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
if (!data) { if (!data)
ret = -ENOMEM; return -ENOMEM;
goto err;
}
mutex_init(&data->lock);
data->regmap = regmap; data->regmap = regmap;
dev_set_drvdata(dev, data); dev_set_drvdata(dev, data);
ret = abb5zes3_rtc_check_setup(dev); ret = abb5zes3_rtc_check_setup(dev);
if (ret) if (ret)
goto err; return ret;
data->rtc = devm_rtc_allocate_device(dev); data->rtc = devm_rtc_allocate_device(dev);
ret = PTR_ERR_OR_ZERO(data->rtc); ret = PTR_ERR_OR_ZERO(data->rtc);
if (ret) { if (ret) {
dev_err(dev, "%s: unable to allocate RTC device (%d)\n", dev_err(dev, "%s: unable to allocate RTC device (%d)\n",
__func__, ret); __func__, ret);
goto err; return ret;
} }
if (client->irq > 0) { if (client->irq > 0) {
ret = devm_request_threaded_irq(dev, client->irq, NULL, ret = devm_request_threaded_irq(dev, client->irq, NULL,
_abb5zes3_rtc_interrupt, _abb5zes3_rtc_interrupt,
IRQF_SHARED|IRQF_ONESHOT, IRQF_SHARED | IRQF_ONESHOT,
DRV_NAME, client); DRV_NAME, client);
if (!ret) { if (!ret) {
device_init_wakeup(dev, true); device_init_wakeup(dev, true);
...@@ -949,8 +886,8 @@ static int abb5zes3_probe(struct i2c_client *client, ...@@ -949,8 +886,8 @@ static int abb5zes3_probe(struct i2c_client *client,
if (!data->battery_low && data->irq) { if (!data->battery_low && data->irq) {
ret = _abb5zes3_rtc_battery_low_irq_enable(regmap, true); ret = _abb5zes3_rtc_battery_low_irq_enable(regmap, true);
if (ret) { if (ret) {
dev_err(dev, "%s: enabling battery low interrupt " dev_err(dev, "%s: enabling battery low interrupt generation failed (%d)\n",
"generation failed (%d)\n", __func__, ret); __func__, ret);
goto err; goto err;
} }
} }
...@@ -958,7 +895,7 @@ static int abb5zes3_probe(struct i2c_client *client, ...@@ -958,7 +895,7 @@ static int abb5zes3_probe(struct i2c_client *client,
ret = rtc_register_device(data->rtc); ret = rtc_register_device(data->rtc);
err: err:
if (ret && data && data->irq) if (ret && data->irq)
device_init_wakeup(dev, false); device_init_wakeup(dev, false);
return ret; return ret;
} }
......
// SPDX-License-Identifier: GPL-2.0
/* /*
* Copyright (C) 2007-2009 ST-Ericsson AB * Copyright (C) 2007-2009 ST-Ericsson AB
* License terms: GNU General Public License (GPL) version 2
* RTC clock driver for the AB3100 Analog Baseband Chip * RTC clock driver for the AB3100 Analog Baseband Chip
* Author: Linus Walleij <linus.walleij@stericsson.com> * Author: Linus Walleij <linus.walleij@stericsson.com>
*/ */
...@@ -43,12 +43,12 @@ ...@@ -43,12 +43,12 @@
/* /*
* RTC clock functions and device struct declaration * RTC clock functions and device struct declaration
*/ */
static int ab3100_rtc_set_mmss(struct device *dev, time64_t secs) static int ab3100_rtc_set_time(struct device *dev, struct rtc_time *tm)
{ {
u8 regs[] = {AB3100_TI0, AB3100_TI1, AB3100_TI2, u8 regs[] = {AB3100_TI0, AB3100_TI1, AB3100_TI2,
AB3100_TI3, AB3100_TI4, AB3100_TI5}; AB3100_TI3, AB3100_TI4, AB3100_TI5};
unsigned char buf[6]; unsigned char buf[6];
u64 hw_counter = secs * AB3100_RTC_CLOCK_RATE * 2; u64 hw_counter = rtc_tm_to_time64(tm) * AB3100_RTC_CLOCK_RATE * 2;
int err = 0; int err = 0;
int i; int i;
...@@ -192,7 +192,7 @@ static int ab3100_rtc_irq_enable(struct device *dev, unsigned int enabled) ...@@ -192,7 +192,7 @@ static int ab3100_rtc_irq_enable(struct device *dev, unsigned int enabled)
static const struct rtc_class_ops ab3100_rtc_ops = { static const struct rtc_class_ops ab3100_rtc_ops = {
.read_time = ab3100_rtc_read_time, .read_time = ab3100_rtc_read_time,
.set_mmss64 = ab3100_rtc_set_mmss, .set_time = ab3100_rtc_set_time,
.read_alarm = ab3100_rtc_read_alarm, .read_alarm = ab3100_rtc_read_alarm,
.set_alarm = ab3100_rtc_set_alarm, .set_alarm = ab3100_rtc_set_alarm,
.alarm_irq_enable = ab3100_rtc_irq_enable, .alarm_irq_enable = ab3100_rtc_irq_enable,
...@@ -228,15 +228,17 @@ static int __init ab3100_rtc_probe(struct platform_device *pdev) ...@@ -228,15 +228,17 @@ static int __init ab3100_rtc_probe(struct platform_device *pdev)
/* Ignore any error on this write */ /* Ignore any error on this write */
} }
rtc = devm_rtc_device_register(&pdev->dev, "ab3100-rtc", rtc = devm_rtc_allocate_device(&pdev->dev);
&ab3100_rtc_ops, THIS_MODULE); if (IS_ERR(rtc))
if (IS_ERR(rtc)) { return PTR_ERR(rtc);
err = PTR_ERR(rtc);
return err; rtc->ops = &ab3100_rtc_ops;
} /* 48bit counter at (AB3100_RTC_CLOCK_RATE * 2) */
rtc->range_max = U32_MAX;
platform_set_drvdata(pdev, rtc); platform_set_drvdata(pdev, rtc);
return 0; return rtc_register_device(rtc);
} }
static struct platform_driver ab3100_rtc_driver = { static struct platform_driver ab3100_rtc_driver = {
......
// SPDX-License-Identifier: GPL-2.0
/* /*
* A driver for the I2C members of the Abracon AB x8xx RTC family, * A driver for the I2C members of the Abracon AB x8xx RTC family,
* and compatible: AB 1805 and AB 0805 * and compatible: AB 1805 and AB 0805
...@@ -7,10 +8,6 @@ ...@@ -7,10 +8,6 @@
* Author: Philippe De Muyter <phdm@macqel.be> * Author: Philippe De Muyter <phdm@macqel.be>
* Author: Alexandre Belloni <alexandre.belloni@bootlin.com> * Author: Alexandre Belloni <alexandre.belloni@bootlin.com>
* *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
*/ */
#include <linux/bcd.h> #include <linux/bcd.h>
...@@ -404,7 +401,7 @@ static ssize_t autocalibration_store(struct device *dev, ...@@ -404,7 +401,7 @@ static ssize_t autocalibration_store(struct device *dev,
return -EINVAL; return -EINVAL;
} }
retval = abx80x_rtc_set_autocalibration(dev, autocalibration); retval = abx80x_rtc_set_autocalibration(dev->parent, autocalibration);
return retval ? retval : count; return retval ? retval : count;
} }
...@@ -414,7 +411,7 @@ static ssize_t autocalibration_show(struct device *dev, ...@@ -414,7 +411,7 @@ static ssize_t autocalibration_show(struct device *dev,
{ {
int autocalibration = 0; int autocalibration = 0;
autocalibration = abx80x_rtc_get_autocalibration(dev); autocalibration = abx80x_rtc_get_autocalibration(dev->parent);
if (autocalibration < 0) { if (autocalibration < 0) {
dev_err(dev, "Failed to read RTC autocalibration\n"); dev_err(dev, "Failed to read RTC autocalibration\n");
sprintf(buf, "0\n"); sprintf(buf, "0\n");
...@@ -430,7 +427,7 @@ static ssize_t oscillator_store(struct device *dev, ...@@ -430,7 +427,7 @@ static ssize_t oscillator_store(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev->parent);
int retval, flags, rc_mode = 0; int retval, flags, rc_mode = 0;
if (strncmp(buf, "rc", 2) == 0) { if (strncmp(buf, "rc", 2) == 0) {
...@@ -472,7 +469,7 @@ static ssize_t oscillator_show(struct device *dev, ...@@ -472,7 +469,7 @@ static ssize_t oscillator_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
int rc_mode = 0; int rc_mode = 0;
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev->parent);
rc_mode = abx80x_is_rc_mode(client); rc_mode = abx80x_is_rc_mode(client);
...@@ -592,13 +589,6 @@ static int abx80x_dt_trickle_cfg(struct device_node *np) ...@@ -592,13 +589,6 @@ static int abx80x_dt_trickle_cfg(struct device_node *np)
return (trickle_cfg | i); return (trickle_cfg | i);
} }
static void rtc_calib_remove_sysfs_group(void *_dev)
{
struct device *dev = _dev;
sysfs_remove_group(&dev->kobj, &rtc_calib_attr_group);
}
#ifdef CONFIG_WATCHDOG #ifdef CONFIG_WATCHDOG
static inline u8 timeout_bits(unsigned int timeout) static inline u8 timeout_bits(unsigned int timeout)
...@@ -851,32 +841,14 @@ static int abx80x_probe(struct i2c_client *client, ...@@ -851,32 +841,14 @@ static int abx80x_probe(struct i2c_client *client,
} }
} }
/* Export sysfs entries */ err = rtc_add_group(priv->rtc, &rtc_calib_attr_group);
err = sysfs_create_group(&(&client->dev)->kobj, &rtc_calib_attr_group);
if (err) { if (err) {
dev_err(&client->dev, "Failed to create sysfs group: %d\n", dev_err(&client->dev, "Failed to create sysfs group: %d\n",
err); err);
return err; return err;
} }
err = devm_add_action_or_reset(&client->dev, return rtc_register_device(priv->rtc);
rtc_calib_remove_sysfs_group,
&client->dev);
if (err) {
dev_err(&client->dev,
"Failed to add sysfs cleanup action: %d\n",
err);
return err;
}
err = rtc_register_device(priv->rtc);
return err;
}
static int abx80x_remove(struct i2c_client *client)
{
return 0;
} }
static const struct i2c_device_id abx80x_id[] = { static const struct i2c_device_id abx80x_id[] = {
...@@ -899,7 +871,6 @@ static struct i2c_driver abx80x_driver = { ...@@ -899,7 +871,6 @@ static struct i2c_driver abx80x_driver = {
.name = "rtc-abx80x", .name = "rtc-abx80x",
}, },
.probe = abx80x_probe, .probe = abx80x_probe,
.remove = abx80x_remove,
.id_table = abx80x_id, .id_table = abx80x_id,
}; };
......
// SPDX-License-Identifier: GPL-2.0+
// Copyright 2015 IBM Corp.
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/rtc.h>
#include <linux/io.h>
struct aspeed_rtc {
struct rtc_device *rtc_dev;
void __iomem *base;
};
#define RTC_TIME 0x00
#define RTC_YEAR 0x04
#define RTC_CTRL 0x10
#define RTC_UNLOCK BIT(1)
#define RTC_ENABLE BIT(0)
static int aspeed_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
struct aspeed_rtc *rtc = dev_get_drvdata(dev);
unsigned int cent, year;
u32 reg1, reg2;
if (!(readl(rtc->base + RTC_CTRL) & RTC_ENABLE)) {
dev_dbg(dev, "%s failing as rtc disabled\n", __func__);
return -EINVAL;
}
do {
reg2 = readl(rtc->base + RTC_YEAR);
reg1 = readl(rtc->base + RTC_TIME);
} while (reg2 != readl(rtc->base + RTC_YEAR));
tm->tm_mday = (reg1 >> 24) & 0x1f;
tm->tm_hour = (reg1 >> 16) & 0x1f;
tm->tm_min = (reg1 >> 8) & 0x3f;
tm->tm_sec = (reg1 >> 0) & 0x3f;
cent = (reg2 >> 16) & 0x1f;
year = (reg2 >> 8) & 0x7f;
tm->tm_mon = ((reg2 >> 0) & 0x0f) - 1;
tm->tm_year = year + (cent * 100) - 1900;
dev_dbg(dev, "%s %ptR", __func__, tm);
return 0;
}
static int aspeed_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
struct aspeed_rtc *rtc = dev_get_drvdata(dev);
u32 reg1, reg2, ctrl;
int year, cent;
cent = (tm->tm_year + 1900) / 100;
year = tm->tm_year % 100;
reg1 = (tm->tm_mday << 24) | (tm->tm_hour << 16) | (tm->tm_min << 8) |
tm->tm_sec;
reg2 = ((cent & 0x1f) << 16) | ((year & 0x7f) << 8) |
((tm->tm_mon + 1) & 0xf);
ctrl = readl(rtc->base + RTC_CTRL);
writel(ctrl | RTC_UNLOCK, rtc->base + RTC_CTRL);
writel(reg1, rtc->base + RTC_TIME);
writel(reg2, rtc->base + RTC_YEAR);
/* Re-lock and ensure enable is set now that a time is programmed */
writel(ctrl | RTC_ENABLE, rtc->base + RTC_CTRL);
return 0;
}
static const struct rtc_class_ops aspeed_rtc_ops = {
.read_time = aspeed_rtc_read_time,
.set_time = aspeed_rtc_set_time,
};
static int aspeed_rtc_probe(struct platform_device *pdev)
{
struct aspeed_rtc *rtc;
struct resource *res;
int ret;
rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
if (!rtc)
return -ENOMEM;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
rtc->base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(rtc->base))
return PTR_ERR(rtc->base);
rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev);
if (IS_ERR(rtc->rtc_dev))
return PTR_ERR(rtc->rtc_dev);
platform_set_drvdata(pdev, rtc);
rtc->rtc_dev->ops = &aspeed_rtc_ops;
rtc->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_1900;
rtc->rtc_dev->range_max = 38814989399LL; /* 3199-12-31 23:59:59 */
ret = rtc_register_device(rtc->rtc_dev);
if (ret)
return ret;
return 0;
}
static const struct of_device_id aspeed_rtc_match[] = {
{ .compatible = "aspeed,ast2400-rtc", },
{ .compatible = "aspeed,ast2500-rtc", },
{ .compatible = "aspeed,ast2600-rtc", },
{}
};
MODULE_DEVICE_TABLE(of, aspeed_rtc_match);
static struct platform_driver aspeed_rtc_driver = {
.driver = {
.name = "aspeed-rtc",
.of_match_table = of_match_ptr(aspeed_rtc_match),
},
};
module_platform_driver_probe(aspeed_rtc_driver, aspeed_rtc_probe);
MODULE_DESCRIPTION("ASPEED RTC driver");
MODULE_AUTHOR("Joel Stanley <joel@jms.id.au>");
MODULE_LICENSE("GPL");
// SPDX-License-Identifier: GPL-2.0+
/* /*
* "RTT as Real Time Clock" driver for AT91SAM9 SoC family * "RTT as Real Time Clock" driver for AT91SAM9 SoC family
* *
* (C) 2007 Michel Benoit * (C) 2007 Michel Benoit
* *
* Based on rtc-at91rm9200.c by Rick Bronson * Based on rtc-at91rm9200.c by Rick Bronson
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/ */
#include <linux/clk.h> #include <linux/clk.h>
...@@ -47,21 +43,21 @@ ...@@ -47,21 +43,21 @@
* registers available, likewise usable for more than "RTC" support. * registers available, likewise usable for more than "RTC" support.
*/ */
#define AT91_RTT_MR 0x00 /* Real-time Mode Register */ #define AT91_RTT_MR 0x00 /* Real-time Mode Register */
#define AT91_RTT_RTPRES (0xffff << 0) /* Real-time Timer Prescaler Value */ #define AT91_RTT_RTPRES (0xffff << 0) /* Timer Prescaler Value */
#define AT91_RTT_ALMIEN (1 << 16) /* Alarm Interrupt Enable */ #define AT91_RTT_ALMIEN BIT(16) /* Alarm Interrupt Enable */
#define AT91_RTT_RTTINCIEN (1 << 17) /* Real Time Timer Increment Interrupt Enable */ #define AT91_RTT_RTTINCIEN BIT(17) /* Increment Interrupt Enable */
#define AT91_RTT_RTTRST (1 << 18) /* Real Time Timer Restart */ #define AT91_RTT_RTTRST BIT(18) /* Timer Restart */
#define AT91_RTT_AR 0x04 /* Real-time Alarm Register */ #define AT91_RTT_AR 0x04 /* Real-time Alarm Register */
#define AT91_RTT_ALMV (0xffffffff) /* Alarm Value */ #define AT91_RTT_ALMV (0xffffffff) /* Alarm Value */
#define AT91_RTT_VR 0x08 /* Real-time Value Register */ #define AT91_RTT_VR 0x08 /* Real-time Value Register */
#define AT91_RTT_CRTV (0xffffffff) /* Current Real-time Value */ #define AT91_RTT_CRTV (0xffffffff) /* Current Real-time Value */
#define AT91_RTT_SR 0x0c /* Real-time Status Register */ #define AT91_RTT_SR 0x0c /* Real-time Status Register */
#define AT91_RTT_ALMS (1 << 0) /* Real-time Alarm Status */ #define AT91_RTT_ALMS BIT(0) /* Alarm Status */
#define AT91_RTT_RTTINC (1 << 1) /* Real-time Timer Increment */ #define AT91_RTT_RTTINC BIT(1) /* Timer Increment */
/* /*
* We store ALARM_DISABLED in ALMV to record that no alarm is set. * We store ALARM_DISABLED in ALMV to record that no alarm is set.
...@@ -69,14 +65,13 @@ ...@@ -69,14 +65,13 @@
*/ */
#define ALARM_DISABLED ((u32)~0) #define ALARM_DISABLED ((u32)~0)
struct sam9_rtc { struct sam9_rtc {
void __iomem *rtt; void __iomem *rtt;
struct rtc_device *rtcdev; struct rtc_device *rtcdev;
u32 imr; u32 imr;
struct regmap *gpbr; struct regmap *gpbr;
unsigned int gpbr_offset; unsigned int gpbr_offset;
int irq; int irq;
struct clk *sclk; struct clk *sclk;
bool suspended; bool suspended;
unsigned long events; unsigned long events;
...@@ -122,7 +117,7 @@ static int at91_rtc_readtime(struct device *dev, struct rtc_time *tm) ...@@ -122,7 +117,7 @@ static int at91_rtc_readtime(struct device *dev, struct rtc_time *tm)
if (secs != secs2) if (secs != secs2)
secs = rtt_readl(rtc, VR); secs = rtt_readl(rtc, VR);
rtc_time_to_tm(offset + secs, tm); rtc_time64_to_tm(offset + secs, tm);
dev_dbg(dev, "%s: %ptR\n", __func__, tm); dev_dbg(dev, "%s: %ptR\n", __func__, tm);
...@@ -135,15 +130,12 @@ static int at91_rtc_readtime(struct device *dev, struct rtc_time *tm) ...@@ -135,15 +130,12 @@ static int at91_rtc_readtime(struct device *dev, struct rtc_time *tm)
static int at91_rtc_settime(struct device *dev, struct rtc_time *tm) static int at91_rtc_settime(struct device *dev, struct rtc_time *tm)
{ {
struct sam9_rtc *rtc = dev_get_drvdata(dev); struct sam9_rtc *rtc = dev_get_drvdata(dev);
int err;
u32 offset, alarm, mr; u32 offset, alarm, mr;
unsigned long secs; unsigned long secs;
dev_dbg(dev, "%s: %ptR\n", __func__, tm); dev_dbg(dev, "%s: %ptR\n", __func__, tm);
err = rtc_tm_to_time(tm, &secs); secs = rtc_tm_to_time64(tm);
if (err != 0)
return err;
mr = rtt_readl(rtc, MR); mr = rtt_readl(rtc, MR);
...@@ -193,7 +185,7 @@ static int at91_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm) ...@@ -193,7 +185,7 @@ static int at91_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
memset(alrm, 0, sizeof(*alrm)); memset(alrm, 0, sizeof(*alrm));
if (alarm != ALARM_DISABLED && offset != 0) { if (alarm != ALARM_DISABLED && offset != 0) {
rtc_time_to_tm(offset + alarm, tm); rtc_time64_to_tm(offset + alarm, tm);
dev_dbg(dev, "%s: %ptR\n", __func__, tm); dev_dbg(dev, "%s: %ptR\n", __func__, tm);
...@@ -211,11 +203,8 @@ static int at91_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm) ...@@ -211,11 +203,8 @@ static int at91_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
unsigned long secs; unsigned long secs;
u32 offset; u32 offset;
u32 mr; u32 mr;
int err;
err = rtc_tm_to_time(tm, &secs); secs = rtc_tm_to_time64(tm);
if (err != 0)
return err;
offset = gpbr_readl(rtc); offset = gpbr_readl(rtc);
if (offset == 0) { if (offset == 0) {
...@@ -263,7 +252,7 @@ static int at91_rtc_proc(struct device *dev, struct seq_file *seq) ...@@ -263,7 +252,7 @@ static int at91_rtc_proc(struct device *dev, struct seq_file *seq)
u32 mr = rtt_readl(rtc, MR); u32 mr = rtt_readl(rtc, MR);
seq_printf(seq, "update_IRQ\t: %s\n", seq_printf(seq, "update_IRQ\t: %s\n",
(mr & AT91_RTT_RTTINCIEN) ? "yes" : "no"); (mr & AT91_RTT_RTTINCIEN) ? "yes" : "no");
return 0; return 0;
} }
...@@ -299,7 +288,7 @@ static void at91_rtc_flush_events(struct sam9_rtc *rtc) ...@@ -299,7 +288,7 @@ static void at91_rtc_flush_events(struct sam9_rtc *rtc)
rtc->events = 0; rtc->events = 0;
pr_debug("%s: num=%ld, events=0x%02lx\n", __func__, pr_debug("%s: num=%ld, events=0x%02lx\n", __func__,
rtc->events >> 8, rtc->events & 0x000000FF); rtc->events >> 8, rtc->events & 0x000000FF);
} }
/* /*
...@@ -340,13 +329,6 @@ static const struct rtc_class_ops at91_rtc_ops = { ...@@ -340,13 +329,6 @@ static const struct rtc_class_ops at91_rtc_ops = {
.alarm_irq_enable = at91_rtc_alarm_irq_enable, .alarm_irq_enable = at91_rtc_alarm_irq_enable,
}; };
static const struct regmap_config gpbr_regmap_config = {
.name = "gpbr",
.reg_bits = 32,
.val_bits = 32,
.reg_stride = 4,
};
/* /*
* Initialize and install RTC driver * Initialize and install RTC driver
*/ */
...@@ -357,6 +339,7 @@ static int at91_rtc_probe(struct platform_device *pdev) ...@@ -357,6 +339,7 @@ static int at91_rtc_probe(struct platform_device *pdev)
int ret, irq; int ret, irq;
u32 mr; u32 mr;
unsigned int sclk_rate; unsigned int sclk_rate;
struct of_phandle_args args;
irq = platform_get_irq(pdev, 0); irq = platform_get_irq(pdev, 0);
if (irq < 0) { if (irq < 0) {
...@@ -382,34 +365,14 @@ static int at91_rtc_probe(struct platform_device *pdev) ...@@ -382,34 +365,14 @@ static int at91_rtc_probe(struct platform_device *pdev)
if (IS_ERR(rtc->rtt)) if (IS_ERR(rtc->rtt))
return PTR_ERR(rtc->rtt); return PTR_ERR(rtc->rtt);
if (!pdev->dev.of_node) { ret = of_parse_phandle_with_fixed_args(pdev->dev.of_node,
/* "atmel,rtt-rtc-time-reg", 1, 0,
* TODO: Remove this code chunk when removing non DT board &args);
* support. Remember to remove the gpbr_regmap_config if (ret)
* variable too. return ret;
*/
void __iomem *gpbr;
r = platform_get_resource(pdev, IORESOURCE_MEM, 1);
gpbr = devm_ioremap_resource(&pdev->dev, r);
if (IS_ERR(gpbr))
return PTR_ERR(gpbr);
rtc->gpbr = regmap_init_mmio(NULL, gpbr,
&gpbr_regmap_config);
} else {
struct of_phandle_args args;
ret = of_parse_phandle_with_fixed_args(pdev->dev.of_node,
"atmel,rtt-rtc-time-reg", 1, 0,
&args);
if (ret)
return ret;
rtc->gpbr = syscon_node_to_regmap(args.np);
rtc->gpbr_offset = args.args[0];
}
rtc->gpbr = syscon_node_to_regmap(args.np);
rtc->gpbr_offset = args.args[0];
if (IS_ERR(rtc->gpbr)) { if (IS_ERR(rtc->gpbr)) {
dev_err(&pdev->dev, "failed to retrieve gpbr regmap, aborting.\n"); dev_err(&pdev->dev, "failed to retrieve gpbr regmap, aborting.\n");
return -ENOMEM; return -ENOMEM;
...@@ -444,13 +407,15 @@ static int at91_rtc_probe(struct platform_device *pdev) ...@@ -444,13 +407,15 @@ static int at91_rtc_probe(struct platform_device *pdev)
mr &= ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN); mr &= ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN);
rtt_writel(rtc, MR, mr); rtt_writel(rtc, MR, mr);
rtc->rtcdev = devm_rtc_device_register(&pdev->dev, pdev->name, rtc->rtcdev = devm_rtc_allocate_device(&pdev->dev);
&at91_rtc_ops, THIS_MODULE);
if (IS_ERR(rtc->rtcdev)) { if (IS_ERR(rtc->rtcdev)) {
ret = PTR_ERR(rtc->rtcdev); ret = PTR_ERR(rtc->rtcdev);
goto err_clk; goto err_clk;
} }
rtc->rtcdev->ops = &at91_rtc_ops;
rtc->rtcdev->range_max = U32_MAX;
/* register irq handler after we know what name we'll use */ /* register irq handler after we know what name we'll use */
ret = devm_request_irq(&pdev->dev, rtc->irq, at91_rtc_interrupt, ret = devm_request_irq(&pdev->dev, rtc->irq, at91_rtc_interrupt,
IRQF_SHARED | IRQF_COND_SUSPEND, IRQF_SHARED | IRQF_COND_SUSPEND,
...@@ -468,9 +433,9 @@ static int at91_rtc_probe(struct platform_device *pdev) ...@@ -468,9 +433,9 @@ static int at91_rtc_probe(struct platform_device *pdev)
if (gpbr_readl(rtc) == 0) if (gpbr_readl(rtc) == 0)
dev_warn(&pdev->dev, "%s: SET TIME!\n", dev_warn(&pdev->dev, "%s: SET TIME!\n",
dev_name(&rtc->rtcdev->dev)); dev_name(&rtc->rtcdev->dev));
return 0; return rtc_register_device(rtc->rtcdev);
err_clk: err_clk:
clk_disable_unprepare(rtc->sclk); clk_disable_unprepare(rtc->sclk);
...@@ -528,8 +493,9 @@ static int at91_rtc_suspend(struct device *dev) ...@@ -528,8 +493,9 @@ static int at91_rtc_suspend(struct device *dev)
/* don't let RTTINC cause wakeups */ /* don't let RTTINC cause wakeups */
if (mr & AT91_RTT_RTTINCIEN) if (mr & AT91_RTT_RTTINCIEN)
rtt_writel(rtc, MR, mr & ~AT91_RTT_RTTINCIEN); rtt_writel(rtc, MR, mr & ~AT91_RTT_RTTINCIEN);
} else } else {
rtt_writel(rtc, MR, mr & ~rtc->imr); rtt_writel(rtc, MR, mr & ~rtc->imr);
}
} }
return 0; return 0;
...@@ -561,13 +527,11 @@ static int at91_rtc_resume(struct device *dev) ...@@ -561,13 +527,11 @@ static int at91_rtc_resume(struct device *dev)
static SIMPLE_DEV_PM_OPS(at91_rtc_pm_ops, at91_rtc_suspend, at91_rtc_resume); static SIMPLE_DEV_PM_OPS(at91_rtc_pm_ops, at91_rtc_suspend, at91_rtc_resume);
#ifdef CONFIG_OF
static const struct of_device_id at91_rtc_dt_ids[] = { static const struct of_device_id at91_rtc_dt_ids[] = {
{ .compatible = "atmel,at91sam9260-rtt" }, { .compatible = "atmel,at91sam9260-rtt" },
{ /* sentinel */ } { /* sentinel */ }
}; };
MODULE_DEVICE_TABLE(of, at91_rtc_dt_ids); MODULE_DEVICE_TABLE(of, at91_rtc_dt_ids);
#endif
static struct platform_driver at91_rtc_driver = { static struct platform_driver at91_rtc_driver = {
.probe = at91_rtc_probe, .probe = at91_rtc_probe,
......
...@@ -132,7 +132,7 @@ static int brcmstb_waketmr_gettime(struct device *dev, ...@@ -132,7 +132,7 @@ static int brcmstb_waketmr_gettime(struct device *dev,
wktmr_read(timer, &now); wktmr_read(timer, &now);
rtc_time_to_tm(now.sec, tm); rtc_time64_to_tm(now.sec, tm);
return 0; return 0;
} }
......
// SPDX-License-Identifier: GPL-2.0
/* /*
* Copyright (C) 2007-2009 ST-Ericsson AB * Copyright (C) 2007-2009 ST-Ericsson AB
* License terms: GNU General Public License (GPL) version 2
* Real Time Clock interface for ST-Ericsson AB COH 901 331 RTC. * Real Time Clock interface for ST-Ericsson AB COH 901 331 RTC.
* Author: Linus Walleij <linus.walleij@stericsson.com> * Author: Linus Walleij <linus.walleij@stericsson.com>
* Based on rtc-pl031.c by Deepak Saxena <dsaxena@plexity.net> * Based on rtc-pl031.c by Deepak Saxena <dsaxena@plexity.net>
...@@ -80,21 +80,22 @@ static int coh901331_read_time(struct device *dev, struct rtc_time *tm) ...@@ -80,21 +80,22 @@ static int coh901331_read_time(struct device *dev, struct rtc_time *tm)
clk_enable(rtap->clk); clk_enable(rtap->clk);
/* Check if the time is valid */ /* Check if the time is valid */
if (readl(rtap->virtbase + COH901331_VALID)) { if (!readl(rtap->virtbase + COH901331_VALID)) {
rtc_time_to_tm(readl(rtap->virtbase + COH901331_CUR_TIME), tm);
clk_disable(rtap->clk); clk_disable(rtap->clk);
return 0; return -EINVAL;
} }
rtc_time64_to_tm(readl(rtap->virtbase + COH901331_CUR_TIME), tm);
clk_disable(rtap->clk); clk_disable(rtap->clk);
return -EINVAL; return 0;
} }
static int coh901331_set_mmss(struct device *dev, unsigned long secs) static int coh901331_set_time(struct device *dev, struct rtc_time *tm)
{ {
struct coh901331_port *rtap = dev_get_drvdata(dev); struct coh901331_port *rtap = dev_get_drvdata(dev);
clk_enable(rtap->clk); clk_enable(rtap->clk);
writel(secs, rtap->virtbase + COH901331_SET_TIME); writel(rtc_tm_to_time64(tm), rtap->virtbase + COH901331_SET_TIME);
clk_disable(rtap->clk); clk_disable(rtap->clk);
return 0; return 0;
...@@ -105,7 +106,7 @@ static int coh901331_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) ...@@ -105,7 +106,7 @@ static int coh901331_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
struct coh901331_port *rtap = dev_get_drvdata(dev); struct coh901331_port *rtap = dev_get_drvdata(dev);
clk_enable(rtap->clk); clk_enable(rtap->clk);
rtc_time_to_tm(readl(rtap->virtbase + COH901331_ALARM), &alarm->time); rtc_time64_to_tm(readl(rtap->virtbase + COH901331_ALARM), &alarm->time);
alarm->pending = readl(rtap->virtbase + COH901331_IRQ_EVENT) & 1U; alarm->pending = readl(rtap->virtbase + COH901331_IRQ_EVENT) & 1U;
alarm->enabled = readl(rtap->virtbase + COH901331_IRQ_MASK) & 1U; alarm->enabled = readl(rtap->virtbase + COH901331_IRQ_MASK) & 1U;
clk_disable(rtap->clk); clk_disable(rtap->clk);
...@@ -116,9 +117,8 @@ static int coh901331_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) ...@@ -116,9 +117,8 @@ static int coh901331_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
static int coh901331_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) static int coh901331_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
{ {
struct coh901331_port *rtap = dev_get_drvdata(dev); struct coh901331_port *rtap = dev_get_drvdata(dev);
unsigned long time; unsigned long time = rtc_tm_to_time64(&alarm->time);
rtc_tm_to_time(&alarm->time, &time);
clk_enable(rtap->clk); clk_enable(rtap->clk);
writel(time, rtap->virtbase + COH901331_ALARM); writel(time, rtap->virtbase + COH901331_ALARM);
writel(alarm->enabled, rtap->virtbase + COH901331_IRQ_MASK); writel(alarm->enabled, rtap->virtbase + COH901331_IRQ_MASK);
...@@ -143,7 +143,7 @@ static int coh901331_alarm_irq_enable(struct device *dev, unsigned int enabled) ...@@ -143,7 +143,7 @@ static int coh901331_alarm_irq_enable(struct device *dev, unsigned int enabled)
static const struct rtc_class_ops coh901331_ops = { static const struct rtc_class_ops coh901331_ops = {
.read_time = coh901331_read_time, .read_time = coh901331_read_time,
.set_mmss = coh901331_set_mmss, .set_time = coh901331_set_time,
.read_alarm = coh901331_read_alarm, .read_alarm = coh901331_read_alarm,
.set_alarm = coh901331_set_alarm, .set_alarm = coh901331_set_alarm,
.alarm_irq_enable = coh901331_alarm_irq_enable, .alarm_irq_enable = coh901331_alarm_irq_enable,
...@@ -188,6 +188,13 @@ static int __init coh901331_probe(struct platform_device *pdev) ...@@ -188,6 +188,13 @@ static int __init coh901331_probe(struct platform_device *pdev)
return ret; return ret;
} }
rtap->rtc = devm_rtc_allocate_device(&pdev->dev);
if (IS_ERR(rtap->rtc))
return PTR_ERR(rtap->rtc);
rtap->rtc->ops = &coh901331_ops;
rtap->rtc->range_max = U32_MAX;
/* We enable/disable the clock only to assure it works */ /* We enable/disable the clock only to assure it works */
ret = clk_prepare_enable(rtap->clk); ret = clk_prepare_enable(rtap->clk);
if (ret) { if (ret) {
...@@ -197,12 +204,10 @@ static int __init coh901331_probe(struct platform_device *pdev) ...@@ -197,12 +204,10 @@ static int __init coh901331_probe(struct platform_device *pdev)
clk_disable(rtap->clk); clk_disable(rtap->clk);
platform_set_drvdata(pdev, rtap); platform_set_drvdata(pdev, rtap);
rtap->rtc = devm_rtc_device_register(&pdev->dev, "coh901331",
&coh901331_ops, THIS_MODULE); ret = rtc_register_device(rtap->rtc);
if (IS_ERR(rtap->rtc)) { if (ret)
ret = PTR_ERR(rtap->rtc);
goto out_no_rtc; goto out_no_rtc;
}
return 0; return 0;
......
/* rtc-da9063.c - Real time clock device driver for DA9063 // SPDX-License-Identifier: GPL-2.0+
/*
* Real time clock device driver for DA9063
* Copyright (C) 2013-2015 Dialog Semiconductor Ltd. * Copyright (C) 2013-2015 Dialog Semiconductor Ltd.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/ */
#include <linux/delay.h> #include <linux/delay.h>
...@@ -247,8 +239,8 @@ static int da9063_rtc_read_time(struct device *dev, struct rtc_time *tm) ...@@ -247,8 +239,8 @@ static int da9063_rtc_read_time(struct device *dev, struct rtc_time *tm)
da9063_data_to_tm(data, tm, rtc); da9063_data_to_tm(data, tm, rtc);
rtc_tm_to_time(tm, &tm_secs); tm_secs = rtc_tm_to_time64(tm);
rtc_tm_to_time(&rtc->alarm_time, &al_secs); al_secs = rtc_tm_to_time64(&rtc->alarm_time);
/* handle the rtc synchronisation delay */ /* handle the rtc synchronisation delay */
if (rtc->rtc_sync == true && al_secs - tm_secs == 1) if (rtc->rtc_sync == true && al_secs - tm_secs == 1)
...@@ -472,11 +464,14 @@ static int da9063_rtc_probe(struct platform_device *pdev) ...@@ -472,11 +464,14 @@ static int da9063_rtc_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, rtc); platform_set_drvdata(pdev, rtc);
rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, DA9063_DRVNAME_RTC, rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev);
&da9063_rtc_ops, THIS_MODULE);
if (IS_ERR(rtc->rtc_dev)) if (IS_ERR(rtc->rtc_dev))
return PTR_ERR(rtc->rtc_dev); return PTR_ERR(rtc->rtc_dev);
rtc->rtc_dev->ops = &da9063_rtc_ops;
rtc->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_2000;
rtc->rtc_dev->range_max = RTC_TIMESTAMP_END_2063;
da9063_data_to_tm(data, &rtc->alarm_time, rtc); da9063_data_to_tm(data, &rtc->alarm_time, rtc);
rtc->rtc_sync = false; rtc->rtc_sync = false;
...@@ -496,7 +491,7 @@ static int da9063_rtc_probe(struct platform_device *pdev) ...@@ -496,7 +491,7 @@ static int da9063_rtc_probe(struct platform_device *pdev)
dev_err(&pdev->dev, "Failed to request ALARM IRQ %d: %d\n", dev_err(&pdev->dev, "Failed to request ALARM IRQ %d: %d\n",
irq_alarm, ret); irq_alarm, ret);
return ret; return rtc_register_device(rtc->rtc_dev);
} }
static struct platform_driver da9063_rtc_driver = { static struct platform_driver da9063_rtc_driver = {
......
// SPDX-License-Identifier: GPL-2.0+
/* /*
* Real Time Clock driver for Conexant Digicolor * Real Time Clock driver for Conexant Digicolor
* *
* Copyright (C) 2015 Paradox Innovation Ltd. * Copyright (C) 2015 Paradox Innovation Ltd.
* *
* Author: Baruch Siach <baruch@tkos.co.il> * Author: Baruch Siach <baruch@tkos.co.il>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*/ */
#include <linux/io.h> #include <linux/io.h>
...@@ -106,11 +102,11 @@ static int dc_rtc_read_time(struct device *dev, struct rtc_time *tm) ...@@ -106,11 +102,11 @@ static int dc_rtc_read_time(struct device *dev, struct rtc_time *tm)
return 0; return 0;
} }
static int dc_rtc_set_mmss(struct device *dev, unsigned long secs) static int dc_rtc_set_time(struct device *dev, struct rtc_time *tm)
{ {
struct dc_rtc *rtc = dev_get_drvdata(dev); struct dc_rtc *rtc = dev_get_drvdata(dev);
return dc_rtc_write(rtc, secs); return dc_rtc_write(rtc, rtc_tm_to_time64(tm));
} }
static int dc_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) static int dc_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
...@@ -161,7 +157,7 @@ static int dc_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) ...@@ -161,7 +157,7 @@ static int dc_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
static const struct rtc_class_ops dc_rtc_ops = { static const struct rtc_class_ops dc_rtc_ops = {
.read_time = dc_rtc_read_time, .read_time = dc_rtc_read_time,
.set_mmss = dc_rtc_set_mmss, .set_time = dc_rtc_set_time,
.read_alarm = dc_rtc_read_alarm, .read_alarm = dc_rtc_read_alarm,
.set_alarm = dc_rtc_set_alarm, .set_alarm = dc_rtc_set_alarm,
.alarm_irq_enable = dc_rtc_alarm_irq_enable, .alarm_irq_enable = dc_rtc_alarm_irq_enable,
...@@ -192,6 +188,10 @@ static int __init dc_rtc_probe(struct platform_device *pdev) ...@@ -192,6 +188,10 @@ static int __init dc_rtc_probe(struct platform_device *pdev)
if (IS_ERR(rtc->regs)) if (IS_ERR(rtc->regs))
return PTR_ERR(rtc->regs); return PTR_ERR(rtc->regs);
rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev);
if (IS_ERR(rtc->rtc_dev))
return PTR_ERR(rtc->rtc_dev);
irq = platform_get_irq(pdev, 0); irq = platform_get_irq(pdev, 0);
if (irq < 0) if (irq < 0)
return irq; return irq;
...@@ -200,12 +200,11 @@ static int __init dc_rtc_probe(struct platform_device *pdev) ...@@ -200,12 +200,11 @@ static int __init dc_rtc_probe(struct platform_device *pdev)
return ret; return ret;
platform_set_drvdata(pdev, rtc); platform_set_drvdata(pdev, rtc);
rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, pdev->name,
&dc_rtc_ops, THIS_MODULE);
if (IS_ERR(rtc->rtc_dev))
return PTR_ERR(rtc->rtc_dev);
return 0; rtc->rtc_dev->ops = &dc_rtc_ops;
rtc->rtc_dev->range_max = U32_MAX;
return rtc_register_device(rtc->rtc_dev);
} }
static const struct of_device_id dc_dt_ids[] = { static const struct of_device_id dc_dt_ids[] = {
......
// SPDX-License-Identifier: GPL-2.0+
/* /*
* rtc-dm355evm.c - access battery-backed counter in MSP430 firmware * rtc-dm355evm.c - access battery-backed counter in MSP430 firmware
* *
* Copyright (c) 2008 by David Brownell * Copyright (c) 2008 by David Brownell
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/ */
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/init.h> #include <linux/init.h>
...@@ -78,7 +74,7 @@ static int dm355evm_rtc_read_time(struct device *dev, struct rtc_time *tm) ...@@ -78,7 +74,7 @@ static int dm355evm_rtc_read_time(struct device *dev, struct rtc_time *tm)
dev_dbg(dev, "read timestamp %08x\n", time.value); dev_dbg(dev, "read timestamp %08x\n", time.value);
rtc_time_to_tm(le32_to_cpu(time.value), tm); rtc_time64_to_tm(le32_to_cpu(time.value), tm);
return 0; return 0;
} }
...@@ -88,7 +84,7 @@ static int dm355evm_rtc_set_time(struct device *dev, struct rtc_time *tm) ...@@ -88,7 +84,7 @@ static int dm355evm_rtc_set_time(struct device *dev, struct rtc_time *tm)
unsigned long value; unsigned long value;
int status; int status;
rtc_tm_to_time(tm, &value); value = rtc_tm_to_time64(tm);
time.value = cpu_to_le32(value); time.value = cpu_to_le32(value);
dev_dbg(dev, "write timestamp %08x\n", time.value); dev_dbg(dev, "write timestamp %08x\n", time.value);
...@@ -127,16 +123,16 @@ static int dm355evm_rtc_probe(struct platform_device *pdev) ...@@ -127,16 +123,16 @@ static int dm355evm_rtc_probe(struct platform_device *pdev)
{ {
struct rtc_device *rtc; struct rtc_device *rtc;
rtc = devm_rtc_device_register(&pdev->dev, pdev->name, rtc = devm_rtc_allocate_device(&pdev->dev);
&dm355evm_rtc_ops, THIS_MODULE); if (IS_ERR(rtc))
if (IS_ERR(rtc)) {
dev_err(&pdev->dev, "can't register RTC device, err %ld\n",
PTR_ERR(rtc));
return PTR_ERR(rtc); return PTR_ERR(rtc);
}
platform_set_drvdata(pdev, rtc); platform_set_drvdata(pdev, rtc);
return 0; rtc->ops = &dm355evm_rtc_ops;
rtc->range_max = U32_MAX;
return rtc_register_device(rtc);
} }
/* /*
......
// SPDX-License-Identifier: GPL-2.0
/* /*
* An rtc/i2c driver for the Dallas DS1672 * An rtc/i2c driver for the Dallas DS1672
* Copyright 2005-06 Tower Technologies * Copyright 2005-06 Tower Technologies
* *
* Author: Alessandro Zummo <a.zummo@towertech.it> * Author: Alessandro Zummo <a.zummo@towertech.it>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/ */
#include <linux/i2c.h> #include <linux/i2c.h>
...@@ -21,17 +18,16 @@ ...@@ -21,17 +18,16 @@
#define DS1672_REG_CONTROL_EOSC 0x80 #define DS1672_REG_CONTROL_EOSC 0x80
static struct i2c_driver ds1672_driver;
/* /*
* In the routines that deal directly with the ds1672 hardware, we use * In the routines that deal directly with the ds1672 hardware, we use
* rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch
* Epoch is initialized as 2000. Time is set to UTC. * Time is set to UTC.
*/ */
static int ds1672_get_datetime(struct i2c_client *client, struct rtc_time *tm) static int ds1672_read_time(struct device *dev, struct rtc_time *tm)
{ {
struct i2c_client *client = to_i2c_client(dev);
unsigned long time; unsigned long time;
unsigned char addr = DS1672_REG_CNT_BASE; unsigned char addr = DS1672_REG_CONTROL;
unsigned char buf[4]; unsigned char buf[4];
struct i2c_msg msgs[] = { struct i2c_msg msgs[] = {
...@@ -43,11 +39,25 @@ static int ds1672_get_datetime(struct i2c_client *client, struct rtc_time *tm) ...@@ -43,11 +39,25 @@ static int ds1672_get_datetime(struct i2c_client *client, struct rtc_time *tm)
{/* read date */ {/* read date */
.addr = client->addr, .addr = client->addr,
.flags = I2C_M_RD, .flags = I2C_M_RD,
.len = 4, .len = 1,
.buf = buf .buf = buf
}, },
}; };
/* read control register */
if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) {
dev_warn(&client->dev, "Unable to read the control register\n");
return -EIO;
}
if (buf[0] & DS1672_REG_CONTROL_EOSC) {
dev_warn(&client->dev, "Oscillator not enabled. Set time to enable.\n");
return -EINVAL;
}
addr = DS1672_REG_CNT_BASE;
msgs[1].len = 4;
/* read date registers */ /* read date registers */
if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) { if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) {
dev_err(&client->dev, "%s: read error\n", __func__); dev_err(&client->dev, "%s: read error\n", __func__);
...@@ -61,20 +71,19 @@ static int ds1672_get_datetime(struct i2c_client *client, struct rtc_time *tm) ...@@ -61,20 +71,19 @@ static int ds1672_get_datetime(struct i2c_client *client, struct rtc_time *tm)
time = ((unsigned long)buf[3] << 24) | (buf[2] << 16) | time = ((unsigned long)buf[3] << 24) | (buf[2] << 16) |
(buf[1] << 8) | buf[0]; (buf[1] << 8) | buf[0];
rtc_time_to_tm(time, tm); rtc_time64_to_tm(time, tm);
dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, " dev_dbg(&client->dev, "%s: tm is %ptR\n", __func__, tm);
"mday=%d, mon=%d, year=%d, wday=%d\n",
__func__, tm->tm_sec, tm->tm_min, tm->tm_hour,
tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
return 0; return 0;
} }
static int ds1672_set_mmss(struct i2c_client *client, unsigned long secs) static int ds1672_set_time(struct device *dev, struct rtc_time *tm)
{ {
struct i2c_client *client = to_i2c_client(dev);
int xfer; int xfer;
unsigned char buf[6]; unsigned char buf[6];
unsigned long secs = rtc_tm_to_time64(tm);
buf[0] = DS1672_REG_CNT_BASE; buf[0] = DS1672_REG_CNT_BASE;
buf[1] = secs & 0x000000FF; buf[1] = secs & 0x000000FF;
...@@ -92,71 +101,15 @@ static int ds1672_set_mmss(struct i2c_client *client, unsigned long secs) ...@@ -92,71 +101,15 @@ static int ds1672_set_mmss(struct i2c_client *client, unsigned long secs)
return 0; return 0;
} }
static int ds1672_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
return ds1672_get_datetime(to_i2c_client(dev), tm);
}
static int ds1672_rtc_set_mmss(struct device *dev, unsigned long secs)
{
return ds1672_set_mmss(to_i2c_client(dev), secs);
}
static int ds1672_get_control(struct i2c_client *client, u8 *status)
{
unsigned char addr = DS1672_REG_CONTROL;
struct i2c_msg msgs[] = {
{/* setup read ptr */
.addr = client->addr,
.len = 1,
.buf = &addr
},
{/* read control */
.addr = client->addr,
.flags = I2C_M_RD,
.len = 1,
.buf = status
},
};
/* read control register */
if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) {
dev_err(&client->dev, "%s: read error\n", __func__);
return -EIO;
}
return 0;
}
/* following are the sysfs callback functions */
static ssize_t show_control(struct device *dev, struct device_attribute *attr,
char *buf)
{
struct i2c_client *client = to_i2c_client(dev);
u8 control;
int err;
err = ds1672_get_control(client, &control);
if (err)
return err;
return sprintf(buf, "%s\n", (control & DS1672_REG_CONTROL_EOSC)
? "disabled" : "enabled");
}
static DEVICE_ATTR(control, S_IRUGO, show_control, NULL);
static const struct rtc_class_ops ds1672_rtc_ops = { static const struct rtc_class_ops ds1672_rtc_ops = {
.read_time = ds1672_rtc_read_time, .read_time = ds1672_read_time,
.set_mmss = ds1672_rtc_set_mmss, .set_time = ds1672_set_time,
}; };
static int ds1672_probe(struct i2c_client *client, static int ds1672_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
int err = 0; int err = 0;
u8 control;
struct rtc_device *rtc; struct rtc_device *rtc;
dev_dbg(&client->dev, "%s\n", __func__); dev_dbg(&client->dev, "%s\n", __func__);
...@@ -164,29 +117,21 @@ static int ds1672_probe(struct i2c_client *client, ...@@ -164,29 +117,21 @@ static int ds1672_probe(struct i2c_client *client,
if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
return -ENODEV; return -ENODEV;
rtc = devm_rtc_device_register(&client->dev, ds1672_driver.driver.name, rtc = devm_rtc_allocate_device(&client->dev);
&ds1672_rtc_ops, THIS_MODULE);
if (IS_ERR(rtc)) if (IS_ERR(rtc))
return PTR_ERR(rtc); return PTR_ERR(rtc);
i2c_set_clientdata(client, rtc); rtc->ops = &ds1672_rtc_ops;
rtc->range_max = U32_MAX;
/* read control register */ err = rtc_register_device(rtc);
err = ds1672_get_control(client, &control); if (err)
if (err) { return err;
dev_warn(&client->dev, "Unable to read the control register\n");
}
if (control & DS1672_REG_CONTROL_EOSC) if (IS_ERR(rtc))
dev_warn(&client->dev, "Oscillator not enabled. " return PTR_ERR(rtc);
"Set time to enable.\n");
/* Register sysfs hooks */ i2c_set_clientdata(client, rtc);
err = device_create_file(&client->dev, &dev_attr_control);
if (err)
dev_err(&client->dev, "Unable to create sysfs entry: %s\n",
dev_attr_control.attr.name);
return 0; return 0;
} }
......
...@@ -191,42 +191,6 @@ ds1685_rtc_end_data_access(struct ds1685_priv *rtc) ...@@ -191,42 +191,6 @@ ds1685_rtc_end_data_access(struct ds1685_priv *rtc)
(rtc->read(rtc, RTC_CTRL_B) & ~(RTC_CTRL_B_SET))); (rtc->read(rtc, RTC_CTRL_B) & ~(RTC_CTRL_B_SET)));
} }
/**
* ds1685_rtc_begin_ctrl_access - prepare the rtc for ctrl access.
* @rtc: pointer to the ds1685 rtc structure.
* @flags: irq flags variable for spin_lock_irqsave.
*
* This takes several steps to prepare the rtc for access to read just the
* control registers:
* - Sets a spinlock on the rtc IRQ.
* - Switches the rtc to bank 1. This allows access to the two extended
* control registers.
*
* Only use this where you are certain another lock will not be held.
*/
static inline void
ds1685_rtc_begin_ctrl_access(struct ds1685_priv *rtc, unsigned long *flags)
{
spin_lock_irqsave(&rtc->lock, *flags);
ds1685_rtc_switch_to_bank1(rtc);
}
/**
* ds1685_rtc_end_ctrl_access - end ctrl access on the rtc.
* @rtc: pointer to the ds1685 rtc structure.
* @flags: irq flags variable for spin_unlock_irqrestore.
*
* This ends what was started by ds1685_rtc_begin_ctrl_access:
* - Switches the rtc back to bank 0.
* - Unsets the spinlock on the rtc IRQ.
*/
static inline void
ds1685_rtc_end_ctrl_access(struct ds1685_priv *rtc, unsigned long flags)
{
ds1685_rtc_switch_to_bank0(rtc);
spin_unlock_irqrestore(&rtc->lock, flags);
}
/** /**
* ds1685_rtc_get_ssn - retrieve the silicon serial number. * ds1685_rtc_get_ssn - retrieve the silicon serial number.
* @rtc: pointer to the ds1685 rtc structure. * @rtc: pointer to the ds1685 rtc structure.
...@@ -546,10 +510,6 @@ static int ...@@ -546,10 +510,6 @@ static int
ds1685_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) ds1685_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
{ {
struct ds1685_priv *rtc = dev_get_drvdata(dev); struct ds1685_priv *rtc = dev_get_drvdata(dev);
unsigned long flags = 0;
/* Enable/disable the Alarm IRQ-Enable flag. */
spin_lock_irqsave(&rtc->lock, flags);
/* Flip the requisite interrupt-enable bit. */ /* Flip the requisite interrupt-enable bit. */
if (enabled) if (enabled)
...@@ -561,7 +521,6 @@ ds1685_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) ...@@ -561,7 +521,6 @@ ds1685_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
/* Read Control C to clear all the flag bits. */ /* Read Control C to clear all the flag bits. */
rtc->read(rtc, RTC_CTRL_C); rtc->read(rtc, RTC_CTRL_C);
spin_unlock_irqrestore(&rtc->lock, flags);
return 0; return 0;
} }
...@@ -569,98 +528,18 @@ ds1685_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) ...@@ -569,98 +528,18 @@ ds1685_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/* IRQ handler & workqueue. */ /* IRQ handler */
/**
* ds1685_rtc_irq_handler - IRQ handler.
* @irq: IRQ number.
* @dev_id: platform device pointer.
*/
static irqreturn_t
ds1685_rtc_irq_handler(int irq, void *dev_id)
{
struct platform_device *pdev = dev_id;
struct ds1685_priv *rtc = platform_get_drvdata(pdev);
u8 ctrlb, ctrlc;
unsigned long events = 0;
u8 num_irqs = 0;
/* Abort early if the device isn't ready yet (i.e., DEBUG_SHIRQ). */
if (unlikely(!rtc))
return IRQ_HANDLED;
/* Ctrlb holds the interrupt-enable bits and ctrlc the flag bits. */
spin_lock(&rtc->lock);
ctrlb = rtc->read(rtc, RTC_CTRL_B);
ctrlc = rtc->read(rtc, RTC_CTRL_C);
/* Is the IRQF bit set? */
if (likely(ctrlc & RTC_CTRL_C_IRQF)) {
/*
* We need to determine if it was one of the standard
* events: PF, AF, or UF. If so, we handle them and
* update the RTC core.
*/
if (likely(ctrlc & RTC_CTRL_B_PAU_MASK)) {
events = RTC_IRQF;
/* Check for a periodic interrupt. */
if ((ctrlb & RTC_CTRL_B_PIE) &&
(ctrlc & RTC_CTRL_C_PF)) {
events |= RTC_PF;
num_irqs++;
}
/* Check for an alarm interrupt. */
if ((ctrlb & RTC_CTRL_B_AIE) &&
(ctrlc & RTC_CTRL_C_AF)) {
events |= RTC_AF;
num_irqs++;
}
/* Check for an update interrupt. */
if ((ctrlb & RTC_CTRL_B_UIE) &&
(ctrlc & RTC_CTRL_C_UF)) {
events |= RTC_UF;
num_irqs++;
}
rtc_update_irq(rtc->dev, num_irqs, events);
} else {
/*
* One of the "extended" interrupts was received that
* is not recognized by the RTC core. These need to
* be handled in task context as they can call other
* functions and the time spent in irq context needs
* to be minimized. Schedule them into a workqueue
* and inform the RTC core that the IRQs were handled.
*/
spin_unlock(&rtc->lock);
schedule_work(&rtc->work);
rtc_update_irq(rtc->dev, 0, 0);
return IRQ_HANDLED;
}
}
spin_unlock(&rtc->lock);
return events ? IRQ_HANDLED : IRQ_NONE;
}
/** /**
* ds1685_rtc_work_queue - work queue handler. * ds1685_rtc_extended_irq - take care of extended interrupts
* @work: work_struct containing data to work on in task context. * @rtc: pointer to the ds1685 rtc structure.
* @pdev: platform device pointer.
*/ */
static void static void
ds1685_rtc_work_queue(struct work_struct *work) ds1685_rtc_extended_irq(struct ds1685_priv *rtc, struct platform_device *pdev)
{ {
struct ds1685_priv *rtc = container_of(work,
struct ds1685_priv, work);
struct platform_device *pdev = to_platform_device(&rtc->dev->dev);
struct mutex *rtc_mutex = &rtc->dev->ops_lock;
u8 ctrl4a, ctrl4b; u8 ctrl4a, ctrl4b;
mutex_lock(rtc_mutex);
ds1685_rtc_switch_to_bank1(rtc); ds1685_rtc_switch_to_bank1(rtc);
ctrl4a = rtc->read(rtc, RTC_EXT_CTRL_4A); ctrl4a = rtc->read(rtc, RTC_EXT_CTRL_4A);
ctrl4b = rtc->read(rtc, RTC_EXT_CTRL_4B); ctrl4b = rtc->read(rtc, RTC_EXT_CTRL_4B);
...@@ -739,8 +618,76 @@ ds1685_rtc_work_queue(struct work_struct *work) ...@@ -739,8 +618,76 @@ ds1685_rtc_work_queue(struct work_struct *work)
"RAM-Clear IRQ just occurred!\n"); "RAM-Clear IRQ just occurred!\n");
} }
ds1685_rtc_switch_to_bank0(rtc); ds1685_rtc_switch_to_bank0(rtc);
}
/**
* ds1685_rtc_irq_handler - IRQ handler.
* @irq: IRQ number.
* @dev_id: platform device pointer.
*/
static irqreturn_t
ds1685_rtc_irq_handler(int irq, void *dev_id)
{
struct platform_device *pdev = dev_id;
struct ds1685_priv *rtc = platform_get_drvdata(pdev);
struct mutex *rtc_mutex;
u8 ctrlb, ctrlc;
unsigned long events = 0;
u8 num_irqs = 0;
/* Abort early if the device isn't ready yet (i.e., DEBUG_SHIRQ). */
if (unlikely(!rtc))
return IRQ_HANDLED;
rtc_mutex = &rtc->dev->ops_lock;
mutex_lock(rtc_mutex);
/* Ctrlb holds the interrupt-enable bits and ctrlc the flag bits. */
ctrlb = rtc->read(rtc, RTC_CTRL_B);
ctrlc = rtc->read(rtc, RTC_CTRL_C);
/* Is the IRQF bit set? */
if (likely(ctrlc & RTC_CTRL_C_IRQF)) {
/*
* We need to determine if it was one of the standard
* events: PF, AF, or UF. If so, we handle them and
* update the RTC core.
*/
if (likely(ctrlc & RTC_CTRL_B_PAU_MASK)) {
events = RTC_IRQF;
/* Check for a periodic interrupt. */
if ((ctrlb & RTC_CTRL_B_PIE) &&
(ctrlc & RTC_CTRL_C_PF)) {
events |= RTC_PF;
num_irqs++;
}
/* Check for an alarm interrupt. */
if ((ctrlb & RTC_CTRL_B_AIE) &&
(ctrlc & RTC_CTRL_C_AF)) {
events |= RTC_AF;
num_irqs++;
}
/* Check for an update interrupt. */
if ((ctrlb & RTC_CTRL_B_UIE) &&
(ctrlc & RTC_CTRL_C_UF)) {
events |= RTC_UF;
num_irqs++;
}
} else {
/*
* One of the "extended" interrupts was received that
* is not recognized by the RTC core.
*/
ds1685_rtc_extended_irq(rtc, pdev);
}
}
rtc_update_irq(rtc->dev, num_irqs, events);
mutex_unlock(rtc_mutex); mutex_unlock(rtc_mutex);
return events ? IRQ_HANDLED : IRQ_NONE;
} }
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
...@@ -869,11 +816,15 @@ static int ds1685_nvram_read(void *priv, unsigned int pos, void *val, ...@@ -869,11 +816,15 @@ static int ds1685_nvram_read(void *priv, unsigned int pos, void *val,
size_t size) size_t size)
{ {
struct ds1685_priv *rtc = priv; struct ds1685_priv *rtc = priv;
struct mutex *rtc_mutex = &rtc->dev->ops_lock;
ssize_t count; ssize_t count;
unsigned long flags = 0;
u8 *buf = val; u8 *buf = val;
int err;
err = mutex_lock_interruptible(rtc_mutex);
if (err)
return err;
spin_lock_irqsave(&rtc->lock, flags);
ds1685_rtc_switch_to_bank0(rtc); ds1685_rtc_switch_to_bank0(rtc);
/* Read NVRAM in time and bank0 registers. */ /* Read NVRAM in time and bank0 registers. */
...@@ -923,7 +874,7 @@ static int ds1685_nvram_read(void *priv, unsigned int pos, void *val, ...@@ -923,7 +874,7 @@ static int ds1685_nvram_read(void *priv, unsigned int pos, void *val,
ds1685_rtc_switch_to_bank0(rtc); ds1685_rtc_switch_to_bank0(rtc);
} }
#endif /* !CONFIG_RTC_DRV_DS1689 */ #endif /* !CONFIG_RTC_DRV_DS1689 */
spin_unlock_irqrestore(&rtc->lock, flags); mutex_unlock(rtc_mutex);
return 0; return 0;
} }
...@@ -932,11 +883,15 @@ static int ds1685_nvram_write(void *priv, unsigned int pos, void *val, ...@@ -932,11 +883,15 @@ static int ds1685_nvram_write(void *priv, unsigned int pos, void *val,
size_t size) size_t size)
{ {
struct ds1685_priv *rtc = priv; struct ds1685_priv *rtc = priv;
struct mutex *rtc_mutex = &rtc->dev->ops_lock;
ssize_t count; ssize_t count;
unsigned long flags = 0;
u8 *buf = val; u8 *buf = val;
int err;
err = mutex_lock_interruptible(rtc_mutex);
if (err)
return err;
spin_lock_irqsave(&rtc->lock, flags);
ds1685_rtc_switch_to_bank0(rtc); ds1685_rtc_switch_to_bank0(rtc);
/* Write NVRAM in time and bank0 registers. */ /* Write NVRAM in time and bank0 registers. */
...@@ -986,7 +941,7 @@ static int ds1685_nvram_write(void *priv, unsigned int pos, void *val, ...@@ -986,7 +941,7 @@ static int ds1685_nvram_write(void *priv, unsigned int pos, void *val,
ds1685_rtc_switch_to_bank0(rtc); ds1685_rtc_switch_to_bank0(rtc);
} }
#endif /* !CONFIG_RTC_DRV_DS1689 */ #endif /* !CONFIG_RTC_DRV_DS1689 */
spin_unlock_irqrestore(&rtc->lock, flags); mutex_unlock(rtc_mutex);
return 0; return 0;
} }
...@@ -1004,7 +959,7 @@ static ssize_t ...@@ -1004,7 +959,7 @@ static ssize_t
ds1685_rtc_sysfs_battery_show(struct device *dev, ds1685_rtc_sysfs_battery_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct ds1685_priv *rtc = dev_get_drvdata(dev); struct ds1685_priv *rtc = dev_get_drvdata(dev->parent);
u8 ctrld; u8 ctrld;
ctrld = rtc->read(rtc, RTC_CTRL_D); ctrld = rtc->read(rtc, RTC_CTRL_D);
...@@ -1024,7 +979,7 @@ static ssize_t ...@@ -1024,7 +979,7 @@ static ssize_t
ds1685_rtc_sysfs_auxbatt_show(struct device *dev, ds1685_rtc_sysfs_auxbatt_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct ds1685_priv *rtc = dev_get_drvdata(dev); struct ds1685_priv *rtc = dev_get_drvdata(dev->parent);
u8 ctrl4a; u8 ctrl4a;
ds1685_rtc_switch_to_bank1(rtc); ds1685_rtc_switch_to_bank1(rtc);
...@@ -1046,7 +1001,7 @@ static ssize_t ...@@ -1046,7 +1001,7 @@ static ssize_t
ds1685_rtc_sysfs_serial_show(struct device *dev, ds1685_rtc_sysfs_serial_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct ds1685_priv *rtc = dev_get_drvdata(dev); struct ds1685_priv *rtc = dev_get_drvdata(dev->parent);
u8 ssn[8]; u8 ssn[8];
ds1685_rtc_switch_to_bank1(rtc); ds1685_rtc_switch_to_bank1(rtc);
...@@ -1177,9 +1132,7 @@ ds1685_rtc_probe(struct platform_device *pdev) ...@@ -1177,9 +1132,7 @@ ds1685_rtc_probe(struct platform_device *pdev)
if (pdata->plat_post_ram_clear) if (pdata->plat_post_ram_clear)
rtc->post_ram_clear = pdata->plat_post_ram_clear; rtc->post_ram_clear = pdata->plat_post_ram_clear;
/* Init the spinlock, workqueue, & set the driver data. */ /* set the driver data. */
spin_lock_init(&rtc->lock);
INIT_WORK(&rtc->work, ds1685_rtc_work_queue);
platform_set_drvdata(pdev, rtc); platform_set_drvdata(pdev, rtc);
/* Turn the oscillator on if is not already on (DV1 = 1). */ /* Turn the oscillator on if is not already on (DV1 = 1). */
...@@ -1335,22 +1288,23 @@ ds1685_rtc_probe(struct platform_device *pdev) ...@@ -1335,22 +1288,23 @@ ds1685_rtc_probe(struct platform_device *pdev)
*/ */
if (!pdata->no_irq) { if (!pdata->no_irq) {
ret = platform_get_irq(pdev, 0); ret = platform_get_irq(pdev, 0);
if (ret > 0) { if (ret <= 0)
rtc->irq_num = ret;
/* Request an IRQ. */
ret = devm_request_irq(&pdev->dev, rtc->irq_num,
ds1685_rtc_irq_handler,
IRQF_SHARED, pdev->name, pdev);
/* Check to see if something came back. */
if (unlikely(ret)) {
dev_warn(&pdev->dev,
"RTC interrupt not available\n");
rtc->irq_num = 0;
}
} else
return ret; return ret;
rtc->irq_num = ret;
/* Request an IRQ. */
ret = devm_request_threaded_irq(&pdev->dev, rtc->irq_num,
NULL, ds1685_rtc_irq_handler,
IRQF_SHARED | IRQF_ONESHOT,
pdev->name, pdev);
/* Check to see if something came back. */
if (unlikely(ret)) {
dev_warn(&pdev->dev,
"RTC interrupt not available\n");
rtc->irq_num = 0;
}
} }
rtc->no_irq = pdata->no_irq; rtc->no_irq = pdata->no_irq;
...@@ -1397,8 +1351,6 @@ ds1685_rtc_remove(struct platform_device *pdev) ...@@ -1397,8 +1351,6 @@ ds1685_rtc_remove(struct platform_device *pdev)
(rtc->read(rtc, RTC_EXT_CTRL_4A) & (rtc->read(rtc, RTC_EXT_CTRL_4A) &
~(RTC_CTRL_4A_RWK_MASK))); ~(RTC_CTRL_4A_RWK_MASK)));
cancel_work_sync(&rtc->work);
return 0; return 0;
} }
......
/* // SPDX-License-Identifier: GPL-2.0
* Copyright (C) 2012 Sven Schnelle <svens@stackframe.org> // Copyright (C) 2012 Sven Schnelle <svens@stackframe.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
*/
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/module.h> #include <linux/module.h>
...@@ -29,14 +23,6 @@ ...@@ -29,14 +23,6 @@
#define DS2404_COPY_SCRATCHPAD_CMD 0x55 #define DS2404_COPY_SCRATCHPAD_CMD 0x55
#define DS2404_READ_MEMORY_CMD 0xf0 #define DS2404_READ_MEMORY_CMD 0xf0
struct ds2404;
struct ds2404_chip_ops {
int (*map_io)(struct ds2404 *chip, struct platform_device *pdev,
struct ds2404_platform_data *pdata);
void (*unmap_io)(struct ds2404 *chip);
};
#define DS2404_RST 0 #define DS2404_RST 0
#define DS2404_CLK 1 #define DS2404_CLK 1
#define DS2404_DQ 2 #define DS2404_DQ 2
...@@ -48,7 +34,6 @@ struct ds2404_gpio { ...@@ -48,7 +34,6 @@ struct ds2404_gpio {
struct ds2404 { struct ds2404 {
struct ds2404_gpio *gpio; struct ds2404_gpio *gpio;
const struct ds2404_chip_ops *ops;
struct rtc_device *rtc; struct rtc_device *rtc;
}; };
...@@ -87,7 +72,7 @@ static int ds2404_gpio_map(struct ds2404 *chip, struct platform_device *pdev, ...@@ -87,7 +72,7 @@ static int ds2404_gpio_map(struct ds2404 *chip, struct platform_device *pdev,
return err; return err;
} }
static void ds2404_gpio_unmap(struct ds2404 *chip) static void ds2404_gpio_unmap(void *data)
{ {
int i; int i;
...@@ -95,11 +80,6 @@ static void ds2404_gpio_unmap(struct ds2404 *chip) ...@@ -95,11 +80,6 @@ static void ds2404_gpio_unmap(struct ds2404 *chip)
gpio_free(ds2404_gpio[i].gpio); gpio_free(ds2404_gpio[i].gpio);
} }
static const struct ds2404_chip_ops ds2404_gpio_ops = {
.map_io = ds2404_gpio_map,
.unmap_io = ds2404_gpio_unmap,
};
static void ds2404_reset(struct device *dev) static void ds2404_reset(struct device *dev)
{ {
gpio_set_value(ds2404_gpio[DS2404_RST].gpio, 0); gpio_set_value(ds2404_gpio[DS2404_RST].gpio, 0);
...@@ -206,20 +186,20 @@ static int ds2404_read_time(struct device *dev, struct rtc_time *dt) ...@@ -206,20 +186,20 @@ static int ds2404_read_time(struct device *dev, struct rtc_time *dt)
ds2404_read_memory(dev, 0x203, 4, (u8 *)&time); ds2404_read_memory(dev, 0x203, 4, (u8 *)&time);
time = le32_to_cpu(time); time = le32_to_cpu(time);
rtc_time_to_tm(time, dt); rtc_time64_to_tm(time, dt);
return 0; return 0;
} }
static int ds2404_set_mmss(struct device *dev, unsigned long secs) static int ds2404_set_time(struct device *dev, struct rtc_time *dt)
{ {
u32 time = cpu_to_le32(secs); u32 time = cpu_to_le32(rtc_tm_to_time64(dt));
ds2404_write_memory(dev, 0x203, 4, (u8 *)&time); ds2404_write_memory(dev, 0x203, 4, (u8 *)&time);
return 0; return 0;
} }
static const struct rtc_class_ops ds2404_rtc_ops = { static const struct rtc_class_ops ds2404_rtc_ops = {
.read_time = ds2404_read_time, .read_time = ds2404_read_time,
.set_mmss = ds2404_set_mmss, .set_time = ds2404_set_time,
}; };
static int rtc_probe(struct platform_device *pdev) static int rtc_probe(struct platform_device *pdev)
...@@ -232,11 +212,17 @@ static int rtc_probe(struct platform_device *pdev) ...@@ -232,11 +212,17 @@ static int rtc_probe(struct platform_device *pdev)
if (!chip) if (!chip)
return -ENOMEM; return -ENOMEM;
chip->ops = &ds2404_gpio_ops; chip->rtc = devm_rtc_allocate_device(&pdev->dev);
if (IS_ERR(chip->rtc))
return PTR_ERR(chip->rtc);
retval = chip->ops->map_io(chip, pdev, pdata); retval = ds2404_gpio_map(chip, pdev, pdata);
if (retval) if (retval)
goto err_chip; return retval;
retval = devm_add_action_or_reset(&pdev->dev, ds2404_gpio_unmap, chip);
if (retval)
return retval;
dev_info(&pdev->dev, "using GPIOs RST:%d, CLK:%d, DQ:%d\n", dev_info(&pdev->dev, "using GPIOs RST:%d, CLK:%d, DQ:%d\n",
chip->gpio[DS2404_RST].gpio, chip->gpio[DS2404_CLK].gpio, chip->gpio[DS2404_RST].gpio, chip->gpio[DS2404_CLK].gpio,
...@@ -244,34 +230,19 @@ static int rtc_probe(struct platform_device *pdev) ...@@ -244,34 +230,19 @@ static int rtc_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, chip); platform_set_drvdata(pdev, chip);
chip->rtc = devm_rtc_device_register(&pdev->dev, "ds2404", chip->rtc->ops = &ds2404_rtc_ops;
&ds2404_rtc_ops, THIS_MODULE); chip->rtc->range_max = U32_MAX;
if (IS_ERR(chip->rtc)) {
retval = PTR_ERR(chip->rtc);
goto err_io;
}
ds2404_enable_osc(&pdev->dev); retval = rtc_register_device(chip->rtc);
return 0; if (retval)
return retval;
err_io:
chip->ops->unmap_io(chip);
err_chip:
return retval;
}
static int rtc_remove(struct platform_device *dev)
{
struct ds2404 *chip = platform_get_drvdata(dev);
chip->ops->unmap_io(chip);
ds2404_enable_osc(&pdev->dev);
return 0; return 0;
} }
static struct platform_driver rtc_device_driver = { static struct platform_driver rtc_device_driver = {
.probe = rtc_probe, .probe = rtc_probe,
.remove = rtc_remove,
.driver = { .driver = {
.name = "ds2404", .name = "ds2404",
}, },
......
...@@ -48,6 +48,10 @@ ...@@ -48,6 +48,10 @@
# define DS3232_REG_SR_A1F 0x01 # define DS3232_REG_SR_A1F 0x01
#define DS3232_REG_TEMPERATURE 0x11 #define DS3232_REG_TEMPERATURE 0x11
#define DS3232_REG_SRAM_START 0x14
#define DS3232_REG_SRAM_END 0xFF
#define DS3232_REG_SRAM_SIZE 236
struct ds3232 { struct ds3232 {
struct device *dev; struct device *dev;
...@@ -461,11 +465,39 @@ static const struct rtc_class_ops ds3232_rtc_ops = { ...@@ -461,11 +465,39 @@ static const struct rtc_class_ops ds3232_rtc_ops = {
.alarm_irq_enable = ds3232_alarm_irq_enable, .alarm_irq_enable = ds3232_alarm_irq_enable,
}; };
static int ds3232_nvmem_read(void *priv, unsigned int offset, void *val,
size_t bytes)
{
struct regmap *ds3232_regmap = (struct regmap *)priv;
return regmap_bulk_read(ds3232_regmap, DS3232_REG_SRAM_START + offset,
val, bytes);
}
static int ds3232_nvmem_write(void *priv, unsigned int offset, void *val,
size_t bytes)
{
struct regmap *ds3232_regmap = (struct regmap *)priv;
return regmap_bulk_write(ds3232_regmap, DS3232_REG_SRAM_START + offset,
val, bytes);
}
static int ds3232_probe(struct device *dev, struct regmap *regmap, int irq, static int ds3232_probe(struct device *dev, struct regmap *regmap, int irq,
const char *name) const char *name)
{ {
struct ds3232 *ds3232; struct ds3232 *ds3232;
int ret; int ret;
struct nvmem_config nvmem_cfg = {
.name = "ds3232_sram",
.stride = 1,
.size = DS3232_REG_SRAM_SIZE,
.word_size = 1,
.reg_read = ds3232_nvmem_read,
.reg_write = ds3232_nvmem_write,
.priv = regmap,
.type = NVMEM_TYPE_BATTERY_BACKED
};
ds3232 = devm_kzalloc(dev, sizeof(*ds3232), GFP_KERNEL); ds3232 = devm_kzalloc(dev, sizeof(*ds3232), GFP_KERNEL);
if (!ds3232) if (!ds3232)
...@@ -490,6 +522,10 @@ static int ds3232_probe(struct device *dev, struct regmap *regmap, int irq, ...@@ -490,6 +522,10 @@ static int ds3232_probe(struct device *dev, struct regmap *regmap, int irq,
if (IS_ERR(ds3232->rtc)) if (IS_ERR(ds3232->rtc))
return PTR_ERR(ds3232->rtc); return PTR_ERR(ds3232->rtc);
ret = rtc_nvmem_register(ds3232->rtc, &nvmem_cfg);
if(ret)
return ret;
if (ds3232->irq > 0) { if (ds3232->irq > 0) {
ret = devm_request_threaded_irq(dev, ds3232->irq, NULL, ret = devm_request_threaded_irq(dev, ds3232->irq, NULL,
ds3232_irq, ds3232_irq,
...@@ -542,7 +578,7 @@ static int ds3232_i2c_probe(struct i2c_client *client, ...@@ -542,7 +578,7 @@ static int ds3232_i2c_probe(struct i2c_client *client,
static const struct regmap_config config = { static const struct regmap_config config = {
.reg_bits = 8, .reg_bits = 8,
.val_bits = 8, .val_bits = 8,
.max_register = 0x13, .max_register = DS3232_REG_SRAM_END,
}; };
regmap = devm_regmap_init_i2c(client, &config); regmap = devm_regmap_init_i2c(client, &config);
...@@ -609,7 +645,7 @@ static int ds3234_probe(struct spi_device *spi) ...@@ -609,7 +645,7 @@ static int ds3234_probe(struct spi_device *spi)
static const struct regmap_config config = { static const struct regmap_config config = {
.reg_bits = 8, .reg_bits = 8,
.val_bits = 8, .val_bits = 8,
.max_register = 0x13, .max_register = DS3232_REG_SRAM_END,
.write_flag_mask = 0x80, .write_flag_mask = 0x80,
}; };
struct regmap *regmap; struct regmap *regmap;
......
// SPDX-License-Identifier: GPL-2.0
/* /*
* A driver for the RTC embedded in the Cirrus Logic EP93XX processors * A driver for the RTC embedded in the Cirrus Logic EP93XX processors
* Copyright (c) 2006 Tower Technologies * Copyright (c) 2006 Tower Technologies
* *
* Author: Alessandro Zummo <a.zummo@towertech.it> * Author: Alessandro Zummo <a.zummo@towertech.it>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/ */
#include <linux/module.h> #include <linux/module.h>
...@@ -18,27 +15,23 @@ ...@@ -18,27 +15,23 @@
#define EP93XX_RTC_DATA 0x000 #define EP93XX_RTC_DATA 0x000
#define EP93XX_RTC_MATCH 0x004 #define EP93XX_RTC_MATCH 0x004
#define EP93XX_RTC_STATUS 0x008 #define EP93XX_RTC_STATUS 0x008
#define EP93XX_RTC_STATUS_INTR (1<<0) #define EP93XX_RTC_STATUS_INTR BIT(0)
#define EP93XX_RTC_LOAD 0x00C #define EP93XX_RTC_LOAD 0x00C
#define EP93XX_RTC_CONTROL 0x010 #define EP93XX_RTC_CONTROL 0x010
#define EP93XX_RTC_CONTROL_MIE (1<<0) #define EP93XX_RTC_CONTROL_MIE BIT(0)
#define EP93XX_RTC_SWCOMP 0x108 #define EP93XX_RTC_SWCOMP 0x108
#define EP93XX_RTC_SWCOMP_DEL_MASK 0x001f0000 #define EP93XX_RTC_SWCOMP_DEL_MASK 0x001f0000
#define EP93XX_RTC_SWCOMP_DEL_SHIFT 16 #define EP93XX_RTC_SWCOMP_DEL_SHIFT 16
#define EP93XX_RTC_SWCOMP_INT_MASK 0x0000ffff #define EP93XX_RTC_SWCOMP_INT_MASK 0x0000ffff
#define EP93XX_RTC_SWCOMP_INT_SHIFT 0 #define EP93XX_RTC_SWCOMP_INT_SHIFT 0
/*
* struct device dev.platform_data is used to store our private data
* because struct rtc_device does not have a variable to hold it.
*/
struct ep93xx_rtc { struct ep93xx_rtc {
void __iomem *mmio_base; void __iomem *mmio_base;
struct rtc_device *rtc; struct rtc_device *rtc;
}; };
static int ep93xx_rtc_get_swcomp(struct device *dev, unsigned short *preload, static int ep93xx_rtc_get_swcomp(struct device *dev, unsigned short *preload,
unsigned short *delete) unsigned short *delete)
{ {
struct ep93xx_rtc *ep93xx_rtc = dev_get_platdata(dev); struct ep93xx_rtc *ep93xx_rtc = dev_get_platdata(dev);
unsigned long comp; unsigned long comp;
...@@ -63,13 +56,14 @@ static int ep93xx_rtc_read_time(struct device *dev, struct rtc_time *tm) ...@@ -63,13 +56,14 @@ static int ep93xx_rtc_read_time(struct device *dev, struct rtc_time *tm)
time = readl(ep93xx_rtc->mmio_base + EP93XX_RTC_DATA); time = readl(ep93xx_rtc->mmio_base + EP93XX_RTC_DATA);
rtc_time_to_tm(time, tm); rtc_time64_to_tm(time, tm);
return 0; return 0;
} }
static int ep93xx_rtc_set_mmss(struct device *dev, unsigned long secs) static int ep93xx_rtc_set_time(struct device *dev, struct rtc_time *tm)
{ {
struct ep93xx_rtc *ep93xx_rtc = dev_get_platdata(dev); struct ep93xx_rtc *ep93xx_rtc = dev_get_platdata(dev);
unsigned long secs = rtc_tm_to_time64(tm);
writel(secs + 1, ep93xx_rtc->mmio_base + EP93XX_RTC_LOAD); writel(secs + 1, ep93xx_rtc->mmio_base + EP93XX_RTC_LOAD);
return 0; return 0;
...@@ -89,31 +83,31 @@ static int ep93xx_rtc_proc(struct device *dev, struct seq_file *seq) ...@@ -89,31 +83,31 @@ static int ep93xx_rtc_proc(struct device *dev, struct seq_file *seq)
static const struct rtc_class_ops ep93xx_rtc_ops = { static const struct rtc_class_ops ep93xx_rtc_ops = {
.read_time = ep93xx_rtc_read_time, .read_time = ep93xx_rtc_read_time,
.set_mmss = ep93xx_rtc_set_mmss, .set_time = ep93xx_rtc_set_time,
.proc = ep93xx_rtc_proc, .proc = ep93xx_rtc_proc,
}; };
static ssize_t ep93xx_rtc_show_comp_preload(struct device *dev, static ssize_t comp_preload_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
unsigned short preload; unsigned short preload;
ep93xx_rtc_get_swcomp(dev, &preload, NULL); ep93xx_rtc_get_swcomp(dev->parent, &preload, NULL);
return sprintf(buf, "%d\n", preload); return sprintf(buf, "%d\n", preload);
} }
static DEVICE_ATTR(comp_preload, S_IRUGO, ep93xx_rtc_show_comp_preload, NULL); static DEVICE_ATTR_RO(comp_preload);
static ssize_t ep93xx_rtc_show_comp_delete(struct device *dev, static ssize_t comp_delete_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
unsigned short delete; unsigned short delete;
ep93xx_rtc_get_swcomp(dev, NULL, &delete); ep93xx_rtc_get_swcomp(dev->parent, NULL, &delete);
return sprintf(buf, "%d\n", delete); return sprintf(buf, "%d\n", delete);
} }
static DEVICE_ATTR(comp_delete, S_IRUGO, ep93xx_rtc_show_comp_delete, NULL); static DEVICE_ATTR_RO(comp_delete);
static struct attribute *ep93xx_rtc_attrs[] = { static struct attribute *ep93xx_rtc_attrs[] = {
&dev_attr_comp_preload.attr, &dev_attr_comp_preload.attr,
...@@ -140,33 +134,20 @@ static int ep93xx_rtc_probe(struct platform_device *pdev) ...@@ -140,33 +134,20 @@ static int ep93xx_rtc_probe(struct platform_device *pdev)
if (IS_ERR(ep93xx_rtc->mmio_base)) if (IS_ERR(ep93xx_rtc->mmio_base))
return PTR_ERR(ep93xx_rtc->mmio_base); return PTR_ERR(ep93xx_rtc->mmio_base);
pdev->dev.platform_data = ep93xx_rtc;
platform_set_drvdata(pdev, ep93xx_rtc); platform_set_drvdata(pdev, ep93xx_rtc);
ep93xx_rtc->rtc = devm_rtc_device_register(&pdev->dev, ep93xx_rtc->rtc = devm_rtc_allocate_device(&pdev->dev);
pdev->name, &ep93xx_rtc_ops, THIS_MODULE); if (IS_ERR(ep93xx_rtc->rtc))
if (IS_ERR(ep93xx_rtc->rtc)) { return PTR_ERR(ep93xx_rtc->rtc);
err = PTR_ERR(ep93xx_rtc->rtc);
goto exit;
}
err = sysfs_create_group(&pdev->dev.kobj, &ep93xx_rtc_sysfs_files); ep93xx_rtc->rtc->ops = &ep93xx_rtc_ops;
if (err) ep93xx_rtc->rtc->range_max = U32_MAX;
goto exit;
return 0;
exit: err = rtc_add_group(ep93xx_rtc->rtc, &ep93xx_rtc_sysfs_files);
pdev->dev.platform_data = NULL; if (err)
return err; return err;
}
static int ep93xx_rtc_remove(struct platform_device *pdev)
{
sysfs_remove_group(&pdev->dev.kobj, &ep93xx_rtc_sysfs_files);
pdev->dev.platform_data = NULL;
return 0; return rtc_register_device(ep93xx_rtc->rtc);
} }
static struct platform_driver ep93xx_rtc_driver = { static struct platform_driver ep93xx_rtc_driver = {
...@@ -174,7 +155,6 @@ static struct platform_driver ep93xx_rtc_driver = { ...@@ -174,7 +155,6 @@ static struct platform_driver ep93xx_rtc_driver = {
.name = "ep93xx-rtc", .name = "ep93xx-rtc",
}, },
.probe = ep93xx_rtc_probe, .probe = ep93xx_rtc_probe,
.remove = ep93xx_rtc_remove,
}; };
module_platform_driver(ep93xx_rtc_driver); module_platform_driver(ep93xx_rtc_driver);
......
// SPDX-License-Identifier: GPL-2.0
/* drivers/rtc/rtc-goldfish.c /* drivers/rtc/rtc-goldfish.c
* *
* Copyright (C) 2007 Google, Inc. * Copyright (C) 2007 Google, Inc.
* Copyright (C) 2017 Imagination Technologies Ltd. * Copyright (C) 2017 Imagination Technologies Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/ */
#include <linux/io.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/rtc.h> #include <linux/rtc.h>
#include <linux/io.h>
#define TIMER_TIME_LOW 0x00 /* get low bits of current time */ #define TIMER_TIME_LOW 0x00 /* get low bits of current time */
/* and update TIMER_TIME_HIGH */ /* and update TIMER_TIME_HIGH */
...@@ -56,7 +48,7 @@ static int goldfish_rtc_read_alarm(struct device *dev, ...@@ -56,7 +48,7 @@ static int goldfish_rtc_read_alarm(struct device *dev,
do_div(rtc_alarm, NSEC_PER_SEC); do_div(rtc_alarm, NSEC_PER_SEC);
memset(alrm, 0, sizeof(struct rtc_wkalrm)); memset(alrm, 0, sizeof(struct rtc_wkalrm));
rtc_time_to_tm(rtc_alarm, &alrm->time); rtc_time64_to_tm(rtc_alarm, &alrm->time);
if (readl(base + TIMER_ALARM_STATUS)) if (readl(base + TIMER_ALARM_STATUS))
alrm->enabled = 1; alrm->enabled = 1;
...@@ -70,21 +62,15 @@ static int goldfish_rtc_set_alarm(struct device *dev, ...@@ -70,21 +62,15 @@ static int goldfish_rtc_set_alarm(struct device *dev,
struct rtc_wkalrm *alrm) struct rtc_wkalrm *alrm)
{ {
struct goldfish_rtc *rtcdrv; struct goldfish_rtc *rtcdrv;
unsigned long rtc_alarm;
u64 rtc_alarm64; u64 rtc_alarm64;
u64 rtc_status_reg; u64 rtc_status_reg;
void __iomem *base; void __iomem *base;
int ret = 0;
rtcdrv = dev_get_drvdata(dev); rtcdrv = dev_get_drvdata(dev);
base = rtcdrv->base; base = rtcdrv->base;
if (alrm->enabled) { if (alrm->enabled) {
ret = rtc_tm_to_time(&alrm->time, &rtc_alarm); rtc_alarm64 = rtc_tm_to_time64(&alrm->time) * NSEC_PER_SEC;
if (ret != 0)
return ret;
rtc_alarm64 = rtc_alarm * NSEC_PER_SEC;
writel((rtc_alarm64 >> 32), base + TIMER_ALARM_HIGH); writel((rtc_alarm64 >> 32), base + TIMER_ALARM_HIGH);
writel(rtc_alarm64, base + TIMER_ALARM_LOW); writel(rtc_alarm64, base + TIMER_ALARM_LOW);
} else { } else {
...@@ -98,7 +84,7 @@ static int goldfish_rtc_set_alarm(struct device *dev, ...@@ -98,7 +84,7 @@ static int goldfish_rtc_set_alarm(struct device *dev,
writel(1, base + TIMER_CLEAR_ALARM); writel(1, base + TIMER_CLEAR_ALARM);
} }
return ret; return 0;
} }
static int goldfish_rtc_alarm_irq_enable(struct device *dev, static int goldfish_rtc_alarm_irq_enable(struct device *dev,
...@@ -147,7 +133,7 @@ static int goldfish_rtc_read_time(struct device *dev, struct rtc_time *tm) ...@@ -147,7 +133,7 @@ static int goldfish_rtc_read_time(struct device *dev, struct rtc_time *tm)
do_div(time, NSEC_PER_SEC); do_div(time, NSEC_PER_SEC);
rtc_time_to_tm(time, tm); rtc_time64_to_tm(time, tm);
return 0; return 0;
} }
...@@ -156,21 +142,16 @@ static int goldfish_rtc_set_time(struct device *dev, struct rtc_time *tm) ...@@ -156,21 +142,16 @@ static int goldfish_rtc_set_time(struct device *dev, struct rtc_time *tm)
{ {
struct goldfish_rtc *rtcdrv; struct goldfish_rtc *rtcdrv;
void __iomem *base; void __iomem *base;
unsigned long now;
u64 now64; u64 now64;
int ret;
rtcdrv = dev_get_drvdata(dev); rtcdrv = dev_get_drvdata(dev);
base = rtcdrv->base; base = rtcdrv->base;
ret = rtc_tm_to_time(tm, &now); now64 = rtc_tm_to_time64(tm) * NSEC_PER_SEC;
if (ret == 0) { writel((now64 >> 32), base + TIMER_TIME_HIGH);
now64 = now * NSEC_PER_SEC; writel(now64, base + TIMER_TIME_LOW);
writel((now64 >> 32), base + TIMER_TIME_HIGH);
writel(now64, base + TIMER_TIME_LOW);
}
return ret; return 0;
} }
static const struct rtc_class_ops goldfish_rtc_ops = { static const struct rtc_class_ops goldfish_rtc_ops = {
...@@ -205,19 +186,20 @@ static int goldfish_rtc_probe(struct platform_device *pdev) ...@@ -205,19 +186,20 @@ static int goldfish_rtc_probe(struct platform_device *pdev)
if (rtcdrv->irq < 0) if (rtcdrv->irq < 0)
return -ENODEV; return -ENODEV;
rtcdrv->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, rtcdrv->rtc = devm_rtc_allocate_device(&pdev->dev);
&goldfish_rtc_ops,
THIS_MODULE);
if (IS_ERR(rtcdrv->rtc)) if (IS_ERR(rtcdrv->rtc))
return PTR_ERR(rtcdrv->rtc); return PTR_ERR(rtcdrv->rtc);
rtcdrv->rtc->ops = &goldfish_rtc_ops;
rtcdrv->rtc->range_max = U64_MAX / NSEC_PER_SEC;
err = devm_request_irq(&pdev->dev, rtcdrv->irq, err = devm_request_irq(&pdev->dev, rtcdrv->irq,
goldfish_rtc_interrupt, goldfish_rtc_interrupt,
0, pdev->name, rtcdrv); 0, pdev->name, rtcdrv);
if (err) if (err)
return err; return err;
return 0; return rtc_register_device(rtcdrv->rtc);
} }
static const struct of_device_id goldfish_rtc_of_match[] = { static const struct of_device_id goldfish_rtc_of_match[] = {
......
...@@ -205,8 +205,7 @@ static int hid_time_parse_report(struct platform_device *pdev, ...@@ -205,8 +205,7 @@ static int hid_time_parse_report(struct platform_device *pdev,
static int hid_rtc_read_time(struct device *dev, struct rtc_time *tm) static int hid_rtc_read_time(struct device *dev, struct rtc_time *tm)
{ {
unsigned long flags; unsigned long flags;
struct hid_time_state *time_state = struct hid_time_state *time_state = dev_get_drvdata(dev);
platform_get_drvdata(to_platform_device(dev));
int ret; int ret;
reinit_completion(&time_state->comp_last_time); reinit_completion(&time_state->comp_last_time);
......
// SPDX-License-Identifier: GPL-2.0+
/* /*
* Copyright 2008-2009 Freescale Semiconductor, Inc. All Rights Reserved. * Copyright 2008-2009 Freescale Semiconductor, Inc. All Rights Reserved.
* Copyright 2010 Orex Computed Radiography * Copyright 2010 Orex Computed Radiography
*/ */
/*
* The code contained herein is licensed under the GNU General Public
* License. You may obtain a copy of the GNU General Public License
* Version 2 or later at the following locations:
*
* http://www.opensource.org/licenses/gpl-license.html
* http://www.gnu.org/copyleft/gpl.html
*/
/* based on rtc-mc13892.c */
/* /*
* This driver uses the 47-bit 32 kHz counter in the Freescale DryIce block * This driver uses the 47-bit 32 kHz counter in the Freescale DryIce block
* to implement a Linux RTC. Times and alarms are truncated to seconds. * to implement a Linux RTC. Times and alarms are truncated to seconds.
...@@ -552,7 +542,7 @@ static int dryice_rtc_read_time(struct device *dev, struct rtc_time *tm) ...@@ -552,7 +542,7 @@ static int dryice_rtc_read_time(struct device *dev, struct rtc_time *tm)
unsigned long now; unsigned long now;
now = readl(imxdi->ioaddr + DTCMR); now = readl(imxdi->ioaddr + DTCMR);
rtc_time_to_tm(now, tm); rtc_time64_to_tm(now, tm);
return 0; return 0;
} }
...@@ -561,7 +551,7 @@ static int dryice_rtc_read_time(struct device *dev, struct rtc_time *tm) ...@@ -561,7 +551,7 @@ static int dryice_rtc_read_time(struct device *dev, struct rtc_time *tm)
* set the seconds portion of dryice time counter and clear the * set the seconds portion of dryice time counter and clear the
* fractional part. * fractional part.
*/ */
static int dryice_rtc_set_mmss(struct device *dev, unsigned long secs) static int dryice_rtc_set_time(struct device *dev, struct rtc_time *tm)
{ {
struct imxdi_dev *imxdi = dev_get_drvdata(dev); struct imxdi_dev *imxdi = dev_get_drvdata(dev);
u32 dcr, dsr; u32 dcr, dsr;
...@@ -588,7 +578,7 @@ static int dryice_rtc_set_mmss(struct device *dev, unsigned long secs) ...@@ -588,7 +578,7 @@ static int dryice_rtc_set_mmss(struct device *dev, unsigned long secs)
if (rc != 0) if (rc != 0)
return rc; return rc;
rc = di_write_wait(imxdi, secs, DTCMR); rc = di_write_wait(imxdi, rtc_tm_to_time64(tm), DTCMR);
if (rc != 0) if (rc != 0)
return rc; return rc;
...@@ -618,7 +608,7 @@ static int dryice_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) ...@@ -618,7 +608,7 @@ static int dryice_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
u32 dcamr; u32 dcamr;
dcamr = readl(imxdi->ioaddr + DCAMR); dcamr = readl(imxdi->ioaddr + DCAMR);
rtc_time_to_tm(dcamr, &alarm->time); rtc_time64_to_tm(dcamr, &alarm->time);
/* alarm is enabled if the interrupt is enabled */ /* alarm is enabled if the interrupt is enabled */
alarm->enabled = (readl(imxdi->ioaddr + DIER) & DIER_CAIE) != 0; alarm->enabled = (readl(imxdi->ioaddr + DIER) & DIER_CAIE) != 0;
...@@ -640,21 +630,10 @@ static int dryice_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) ...@@ -640,21 +630,10 @@ static int dryice_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
static int dryice_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) static int dryice_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
{ {
struct imxdi_dev *imxdi = dev_get_drvdata(dev); struct imxdi_dev *imxdi = dev_get_drvdata(dev);
unsigned long now;
unsigned long alarm_time;
int rc; int rc;
rc = rtc_tm_to_time(&alarm->time, &alarm_time);
if (rc)
return rc;
/* don't allow setting alarm in the past */
now = readl(imxdi->ioaddr + DTCMR);
if (alarm_time < now)
return -EINVAL;
/* write the new alarm time */ /* write the new alarm time */
rc = di_write_wait(imxdi, (u32)alarm_time, DCAMR); rc = di_write_wait(imxdi, rtc_tm_to_time64(&alarm->time), DCAMR);
if (rc) if (rc)
return rc; return rc;
...@@ -668,7 +647,7 @@ static int dryice_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) ...@@ -668,7 +647,7 @@ static int dryice_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
static const struct rtc_class_ops dryice_rtc_ops = { static const struct rtc_class_ops dryice_rtc_ops = {
.read_time = dryice_rtc_read_time, .read_time = dryice_rtc_read_time,
.set_mmss = dryice_rtc_set_mmss, .set_time = dryice_rtc_set_time,
.alarm_irq_enable = dryice_rtc_alarm_irq_enable, .alarm_irq_enable = dryice_rtc_alarm_irq_enable,
.read_alarm = dryice_rtc_read_alarm, .read_alarm = dryice_rtc_read_alarm,
.set_alarm = dryice_rtc_set_alarm, .set_alarm = dryice_rtc_set_alarm,
...@@ -796,6 +775,10 @@ static int __init dryice_rtc_probe(struct platform_device *pdev) ...@@ -796,6 +775,10 @@ static int __init dryice_rtc_probe(struct platform_device *pdev)
mutex_init(&imxdi->write_mutex); mutex_init(&imxdi->write_mutex);
imxdi->rtc = devm_rtc_allocate_device(&pdev->dev);
if (IS_ERR(imxdi->rtc))
return PTR_ERR(imxdi->rtc);
imxdi->clk = devm_clk_get(&pdev->dev, NULL); imxdi->clk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(imxdi->clk)) if (IS_ERR(imxdi->clk))
return PTR_ERR(imxdi->clk); return PTR_ERR(imxdi->clk);
...@@ -829,12 +812,13 @@ static int __init dryice_rtc_probe(struct platform_device *pdev) ...@@ -829,12 +812,13 @@ static int __init dryice_rtc_probe(struct platform_device *pdev)
} }
platform_set_drvdata(pdev, imxdi); platform_set_drvdata(pdev, imxdi);
imxdi->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
&dryice_rtc_ops, THIS_MODULE); imxdi->rtc->ops = &dryice_rtc_ops;
if (IS_ERR(imxdi->rtc)) { imxdi->rtc->range_max = U32_MAX;
rc = PTR_ERR(imxdi->rtc);
rc = rtc_register_device(imxdi->rtc);
if (rc)
goto err; goto err;
}
return 0; return 0;
......
// SPDX-License-Identifier: GPL-2.0+
/* /*
* Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de> * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de>
* Copyright (C) 2010, Paul Cercueil <paul@crapouillou.net> * Copyright (C) 2010, Paul Cercueil <paul@crapouillou.net>
* JZ4740 SoC RTC driver * JZ4740 SoC RTC driver
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/ */
#include <linux/clk.h> #include <linux/clk.h>
...@@ -20,6 +11,7 @@ ...@@ -20,6 +11,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/of_device.h> #include <linux/of_device.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/pm_wakeirq.h>
#include <linux/reboot.h> #include <linux/reboot.h>
#include <linux/rtc.h> #include <linux/rtc.h>
#include <linux/slab.h> #include <linux/slab.h>
...@@ -156,6 +148,9 @@ static int jz4740_rtc_read_time(struct device *dev, struct rtc_time *time) ...@@ -156,6 +148,9 @@ static int jz4740_rtc_read_time(struct device *dev, struct rtc_time *time)
uint32_t secs, secs2; uint32_t secs, secs2;
int timeout = 5; int timeout = 5;
if (jz4740_rtc_reg_read(rtc, JZ_REG_RTC_SCRATCHPAD) != 0x12345678)
return -EINVAL;
/* If the seconds register is read while it is updated, it can contain a /* If the seconds register is read while it is updated, it can contain a
* bogus value. This can be avoided by making sure that two consecutive * bogus value. This can be avoided by making sure that two consecutive
* reads have the same value. * reads have the same value.
...@@ -171,16 +166,21 @@ static int jz4740_rtc_read_time(struct device *dev, struct rtc_time *time) ...@@ -171,16 +166,21 @@ static int jz4740_rtc_read_time(struct device *dev, struct rtc_time *time)
if (timeout == 0) if (timeout == 0)
return -EIO; return -EIO;
rtc_time_to_tm(secs, time); rtc_time64_to_tm(secs, time);
return 0; return 0;
} }
static int jz4740_rtc_set_mmss(struct device *dev, unsigned long secs) static int jz4740_rtc_set_time(struct device *dev, struct rtc_time *time)
{ {
struct jz4740_rtc *rtc = dev_get_drvdata(dev); struct jz4740_rtc *rtc = dev_get_drvdata(dev);
int ret;
return jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SEC, secs); ret = jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SEC, rtc_tm_to_time64(time));
if (ret)
return ret;
return jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SCRATCHPAD, 0x12345678);
} }
static int jz4740_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) static int jz4740_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
...@@ -196,18 +196,16 @@ static int jz4740_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) ...@@ -196,18 +196,16 @@ static int jz4740_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
alrm->enabled = !!(ctrl & JZ_RTC_CTRL_AE); alrm->enabled = !!(ctrl & JZ_RTC_CTRL_AE);
alrm->pending = !!(ctrl & JZ_RTC_CTRL_AF); alrm->pending = !!(ctrl & JZ_RTC_CTRL_AF);
rtc_time_to_tm(secs, &alrm->time); rtc_time64_to_tm(secs, &alrm->time);
return rtc_valid_tm(&alrm->time); return 0;
} }
static int jz4740_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) static int jz4740_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{ {
int ret; int ret;
struct jz4740_rtc *rtc = dev_get_drvdata(dev); struct jz4740_rtc *rtc = dev_get_drvdata(dev);
unsigned long secs; uint32_t secs = lower_32_bits(rtc_tm_to_time64(&alrm->time));
rtc_tm_to_time(&alrm->time, &secs);
ret = jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SEC_ALARM, secs); ret = jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SEC_ALARM, secs);
if (!ret) if (!ret)
...@@ -225,7 +223,7 @@ static int jz4740_rtc_alarm_irq_enable(struct device *dev, unsigned int enable) ...@@ -225,7 +223,7 @@ static int jz4740_rtc_alarm_irq_enable(struct device *dev, unsigned int enable)
static const struct rtc_class_ops jz4740_rtc_ops = { static const struct rtc_class_ops jz4740_rtc_ops = {
.read_time = jz4740_rtc_read_time, .read_time = jz4740_rtc_read_time,
.set_mmss = jz4740_rtc_set_mmss, .set_time = jz4740_rtc_set_time,
.read_alarm = jz4740_rtc_read_alarm, .read_alarm = jz4740_rtc_read_alarm,
.set_alarm = jz4740_rtc_set_alarm, .set_alarm = jz4740_rtc_set_alarm,
.alarm_irq_enable = jz4740_rtc_alarm_irq_enable, .alarm_irq_enable = jz4740_rtc_alarm_irq_enable,
...@@ -309,7 +307,6 @@ static int jz4740_rtc_probe(struct platform_device *pdev) ...@@ -309,7 +307,6 @@ static int jz4740_rtc_probe(struct platform_device *pdev)
{ {
int ret; int ret;
struct jz4740_rtc *rtc; struct jz4740_rtc *rtc;
uint32_t scratchpad;
struct resource *mem; struct resource *mem;
const struct platform_device_id *id = platform_get_device_id(pdev); const struct platform_device_id *id = platform_get_device_id(pdev);
const struct of_device_id *of_id = of_match_device( const struct of_device_id *of_id = of_match_device(
...@@ -348,10 +345,24 @@ static int jz4740_rtc_probe(struct platform_device *pdev) ...@@ -348,10 +345,24 @@ static int jz4740_rtc_probe(struct platform_device *pdev)
device_init_wakeup(&pdev->dev, 1); device_init_wakeup(&pdev->dev, 1);
rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, ret = dev_pm_set_wake_irq(&pdev->dev, rtc->irq);
&jz4740_rtc_ops, THIS_MODULE); if (ret) {
dev_err(&pdev->dev, "Failed to set wake irq: %d\n", ret);
return ret;
}
rtc->rtc = devm_rtc_allocate_device(&pdev->dev);
if (IS_ERR(rtc->rtc)) { if (IS_ERR(rtc->rtc)) {
ret = PTR_ERR(rtc->rtc); ret = PTR_ERR(rtc->rtc);
dev_err(&pdev->dev, "Failed to allocate rtc device: %d\n", ret);
return ret;
}
rtc->rtc->ops = &jz4740_rtc_ops;
rtc->rtc->range_max = U32_MAX;
ret = rtc_register_device(rtc->rtc);
if (ret) {
dev_err(&pdev->dev, "Failed to register rtc device: %d\n", ret); dev_err(&pdev->dev, "Failed to register rtc device: %d\n", ret);
return ret; return ret;
} }
...@@ -363,16 +374,6 @@ static int jz4740_rtc_probe(struct platform_device *pdev) ...@@ -363,16 +374,6 @@ static int jz4740_rtc_probe(struct platform_device *pdev)
return ret; return ret;
} }
scratchpad = jz4740_rtc_reg_read(rtc, JZ_REG_RTC_SCRATCHPAD);
if (scratchpad != 0x12345678) {
ret = jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SCRATCHPAD, 0x12345678);
ret = jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SEC, 0);
if (ret) {
dev_err(&pdev->dev, "Could not write to RTC registers\n");
return ret;
}
}
if (np && of_device_is_system_power_controller(np)) { if (np && of_device_is_system_power_controller(np)) {
if (!pm_power_off) { if (!pm_power_off) {
/* Default: 60ms */ /* Default: 60ms */
...@@ -397,35 +398,6 @@ static int jz4740_rtc_probe(struct platform_device *pdev) ...@@ -397,35 +398,6 @@ static int jz4740_rtc_probe(struct platform_device *pdev)
return 0; return 0;
} }
#ifdef CONFIG_PM
static int jz4740_rtc_suspend(struct device *dev)
{
struct jz4740_rtc *rtc = dev_get_drvdata(dev);
if (device_may_wakeup(dev))
enable_irq_wake(rtc->irq);
return 0;
}
static int jz4740_rtc_resume(struct device *dev)
{
struct jz4740_rtc *rtc = dev_get_drvdata(dev);
if (device_may_wakeup(dev))
disable_irq_wake(rtc->irq);
return 0;
}
static const struct dev_pm_ops jz4740_pm_ops = {
.suspend = jz4740_rtc_suspend,
.resume = jz4740_rtc_resume,
};
#define JZ4740_RTC_PM_OPS (&jz4740_pm_ops)
#else
#define JZ4740_RTC_PM_OPS NULL
#endif /* CONFIG_PM */
static const struct platform_device_id jz4740_rtc_ids[] = { static const struct platform_device_id jz4740_rtc_ids[] = {
{ "jz4740-rtc", ID_JZ4740 }, { "jz4740-rtc", ID_JZ4740 },
{ "jz4780-rtc", ID_JZ4780 }, { "jz4780-rtc", ID_JZ4780 },
...@@ -437,7 +409,6 @@ static struct platform_driver jz4740_rtc_driver = { ...@@ -437,7 +409,6 @@ static struct platform_driver jz4740_rtc_driver = {
.probe = jz4740_rtc_probe, .probe = jz4740_rtc_probe,
.driver = { .driver = {
.name = "jz4740-rtc", .name = "jz4740-rtc",
.pm = JZ4740_RTC_PM_OPS,
.of_match_table = of_match_ptr(jz4740_rtc_of_match), .of_match_table = of_match_ptr(jz4740_rtc_of_match),
}, },
.id_table = jz4740_rtc_ids, .id_table = jz4740_rtc_ids,
......
// SPDX-License-Identifier: GPL-2.0+
/* /*
* Copyright (C) 2010 NXP Semiconductors * Copyright (C) 2010 NXP Semiconductors
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
#include <linux/kernel.h> #include <linux/kernel.h>
...@@ -47,8 +39,6 @@ ...@@ -47,8 +39,6 @@
#define LPC32XX_RTC_KEY_ONSW_LOADVAL 0xB5C13F27 #define LPC32XX_RTC_KEY_ONSW_LOADVAL 0xB5C13F27
#define RTC_NAME "rtc-lpc32xx"
#define rtc_readl(dev, reg) \ #define rtc_readl(dev, reg) \
__raw_readl((dev)->rtc_base + (reg)) __raw_readl((dev)->rtc_base + (reg))
#define rtc_writel(dev, reg, val) \ #define rtc_writel(dev, reg, val) \
...@@ -68,14 +58,15 @@ static int lpc32xx_rtc_read_time(struct device *dev, struct rtc_time *time) ...@@ -68,14 +58,15 @@ static int lpc32xx_rtc_read_time(struct device *dev, struct rtc_time *time)
struct lpc32xx_rtc *rtc = dev_get_drvdata(dev); struct lpc32xx_rtc *rtc = dev_get_drvdata(dev);
elapsed_sec = rtc_readl(rtc, LPC32XX_RTC_UCOUNT); elapsed_sec = rtc_readl(rtc, LPC32XX_RTC_UCOUNT);
rtc_time_to_tm(elapsed_sec, time); rtc_time64_to_tm(elapsed_sec, time);
return 0; return 0;
} }
static int lpc32xx_rtc_set_mmss(struct device *dev, unsigned long secs) static int lpc32xx_rtc_set_time(struct device *dev, struct rtc_time *time)
{ {
struct lpc32xx_rtc *rtc = dev_get_drvdata(dev); struct lpc32xx_rtc *rtc = dev_get_drvdata(dev);
u32 secs = rtc_tm_to_time64(time);
u32 tmp; u32 tmp;
spin_lock_irq(&rtc->lock); spin_lock_irq(&rtc->lock);
...@@ -97,7 +88,7 @@ static int lpc32xx_rtc_read_alarm(struct device *dev, ...@@ -97,7 +88,7 @@ static int lpc32xx_rtc_read_alarm(struct device *dev,
{ {
struct lpc32xx_rtc *rtc = dev_get_drvdata(dev); struct lpc32xx_rtc *rtc = dev_get_drvdata(dev);
rtc_time_to_tm(rtc_readl(rtc, LPC32XX_RTC_MATCH0), &wkalrm->time); rtc_time64_to_tm(rtc_readl(rtc, LPC32XX_RTC_MATCH0), &wkalrm->time);
wkalrm->enabled = rtc->alarm_enabled; wkalrm->enabled = rtc->alarm_enabled;
wkalrm->pending = !!(rtc_readl(rtc, LPC32XX_RTC_INTSTAT) & wkalrm->pending = !!(rtc_readl(rtc, LPC32XX_RTC_INTSTAT) &
LPC32XX_RTC_INTSTAT_MATCH0); LPC32XX_RTC_INTSTAT_MATCH0);
...@@ -111,13 +102,8 @@ static int lpc32xx_rtc_set_alarm(struct device *dev, ...@@ -111,13 +102,8 @@ static int lpc32xx_rtc_set_alarm(struct device *dev,
struct lpc32xx_rtc *rtc = dev_get_drvdata(dev); struct lpc32xx_rtc *rtc = dev_get_drvdata(dev);
unsigned long alarmsecs; unsigned long alarmsecs;
u32 tmp; u32 tmp;
int ret;
ret = rtc_tm_to_time(&wkalrm->time, &alarmsecs); alarmsecs = rtc_tm_to_time64(&wkalrm->time);
if (ret < 0) {
dev_warn(dev, "Failed to convert time: %d\n", ret);
return ret;
}
spin_lock_irq(&rtc->lock); spin_lock_irq(&rtc->lock);
...@@ -191,7 +177,7 @@ static irqreturn_t lpc32xx_rtc_alarm_interrupt(int irq, void *dev) ...@@ -191,7 +177,7 @@ static irqreturn_t lpc32xx_rtc_alarm_interrupt(int irq, void *dev)
static const struct rtc_class_ops lpc32xx_rtc_ops = { static const struct rtc_class_ops lpc32xx_rtc_ops = {
.read_time = lpc32xx_rtc_read_time, .read_time = lpc32xx_rtc_read_time,
.set_mmss = lpc32xx_rtc_set_mmss, .set_time = lpc32xx_rtc_set_time,
.read_alarm = lpc32xx_rtc_read_alarm, .read_alarm = lpc32xx_rtc_read_alarm,
.set_alarm = lpc32xx_rtc_set_alarm, .set_alarm = lpc32xx_rtc_set_alarm,
.alarm_irq_enable = lpc32xx_rtc_alarm_irq_enable, .alarm_irq_enable = lpc32xx_rtc_alarm_irq_enable,
...@@ -201,21 +187,13 @@ static int lpc32xx_rtc_probe(struct platform_device *pdev) ...@@ -201,21 +187,13 @@ static int lpc32xx_rtc_probe(struct platform_device *pdev)
{ {
struct resource *res; struct resource *res;
struct lpc32xx_rtc *rtc; struct lpc32xx_rtc *rtc;
int rtcirq; int err;
u32 tmp; u32 tmp;
rtcirq = platform_get_irq(pdev, 0);
if (rtcirq < 0) {
dev_warn(&pdev->dev, "Can't get interrupt resource\n");
rtcirq = -1;
}
rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
if (unlikely(!rtc)) if (unlikely(!rtc))
return -ENOMEM; return -ENOMEM;
rtc->irq = rtcirq;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
rtc->rtc_base = devm_ioremap_resource(&pdev->dev, res); rtc->rtc_base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(rtc->rtc_base)) if (IS_ERR(rtc->rtc_base))
...@@ -256,18 +234,25 @@ static int lpc32xx_rtc_probe(struct platform_device *pdev) ...@@ -256,18 +234,25 @@ static int lpc32xx_rtc_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, rtc); platform_set_drvdata(pdev, rtc);
rtc->rtc = devm_rtc_device_register(&pdev->dev, RTC_NAME, rtc->rtc = devm_rtc_allocate_device(&pdev->dev);
&lpc32xx_rtc_ops, THIS_MODULE); if (IS_ERR(rtc->rtc))
if (IS_ERR(rtc->rtc)) {
dev_err(&pdev->dev, "Can't get RTC\n");
return PTR_ERR(rtc->rtc); return PTR_ERR(rtc->rtc);
}
rtc->rtc->ops = &lpc32xx_rtc_ops;
rtc->rtc->range_max = U32_MAX;
err = rtc_register_device(rtc->rtc);
if (err)
return err;
/* /*
* IRQ is enabled after device registration in case alarm IRQ * IRQ is enabled after device registration in case alarm IRQ
* is pending upon suspend exit. * is pending upon suspend exit.
*/ */
if (rtc->irq >= 0) { rtc->irq = platform_get_irq(pdev, 0);
if (rtc->irq < 0) {
dev_warn(&pdev->dev, "Can't get interrupt resource\n");
} else {
if (devm_request_irq(&pdev->dev, rtc->irq, if (devm_request_irq(&pdev->dev, rtc->irq,
lpc32xx_rtc_alarm_interrupt, lpc32xx_rtc_alarm_interrupt,
0, pdev->name, rtc) < 0) { 0, pdev->name, rtc) < 0) {
...@@ -374,7 +359,7 @@ static struct platform_driver lpc32xx_rtc_driver = { ...@@ -374,7 +359,7 @@ static struct platform_driver lpc32xx_rtc_driver = {
.probe = lpc32xx_rtc_probe, .probe = lpc32xx_rtc_probe,
.remove = lpc32xx_rtc_remove, .remove = lpc32xx_rtc_remove,
.driver = { .driver = {
.name = RTC_NAME, .name = "rtc-lpc32xx",
.pm = LPC32XX_RTC_PM_OPS, .pm = LPC32XX_RTC_PM_OPS,
.of_match_table = of_match_ptr(lpc32xx_rtc_match), .of_match_table = of_match_ptr(lpc32xx_rtc_match),
}, },
......
// SPDX-License-Identifier: GPL-2.0
/* /*
* Real Time Clock driver for Freescale MC13XXX PMIC * Real Time Clock driver for Freescale MC13XXX PMIC
* *
* (C) 2009 Sascha Hauer, Pengutronix * (C) 2009 Sascha Hauer, Pengutronix
* (C) 2009 Uwe Kleine-Koenig, Pengutronix * (C) 2009 Uwe Kleine-Koenig, Pengutronix
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/ */
#include <linux/mfd/mc13xxx.h> #include <linux/mfd/mc13xxx.h>
...@@ -89,14 +86,14 @@ static int mc13xxx_rtc_read_time(struct device *dev, struct rtc_time *tm) ...@@ -89,14 +86,14 @@ static int mc13xxx_rtc_read_time(struct device *dev, struct rtc_time *tm)
return 0; return 0;
} }
static int mc13xxx_rtc_set_mmss(struct device *dev, time64_t secs) static int mc13xxx_rtc_set_time(struct device *dev, struct rtc_time *tm)
{ {
struct mc13xxx_rtc *priv = dev_get_drvdata(dev); struct mc13xxx_rtc *priv = dev_get_drvdata(dev);
unsigned int seconds, days; unsigned int seconds, days;
unsigned int alarmseconds; unsigned int alarmseconds;
int ret; int ret;
days = div_s64_rem(secs, SEC_PER_DAY, &seconds); days = div_s64_rem(rtc_tm_to_time64(tm), SEC_PER_DAY, &seconds);
mc13xxx_lock(priv->mc13xxx); mc13xxx_lock(priv->mc13xxx);
...@@ -158,7 +155,7 @@ static int mc13xxx_rtc_set_mmss(struct device *dev, time64_t secs) ...@@ -158,7 +155,7 @@ static int mc13xxx_rtc_set_mmss(struct device *dev, time64_t secs)
static int mc13xxx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) static int mc13xxx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
{ {
struct mc13xxx_rtc *priv = dev_get_drvdata(dev); struct mc13xxx_rtc *priv = dev_get_drvdata(dev);
unsigned seconds, days; unsigned int seconds, days;
time64_t s1970; time64_t s1970;
int enabled, pending; int enabled, pending;
int ret; int ret;
...@@ -253,7 +250,7 @@ static irqreturn_t mc13xxx_rtc_alarm_handler(int irq, void *dev) ...@@ -253,7 +250,7 @@ static irqreturn_t mc13xxx_rtc_alarm_handler(int irq, void *dev)
static const struct rtc_class_ops mc13xxx_rtc_ops = { static const struct rtc_class_ops mc13xxx_rtc_ops = {
.read_time = mc13xxx_rtc_read_time, .read_time = mc13xxx_rtc_read_time,
.set_mmss64 = mc13xxx_rtc_set_mmss, .set_time = mc13xxx_rtc_set_time,
.read_alarm = mc13xxx_rtc_read_alarm, .read_alarm = mc13xxx_rtc_read_alarm,
.set_alarm = mc13xxx_rtc_set_alarm, .set_alarm = mc13xxx_rtc_set_alarm,
.alarm_irq_enable = mc13xxx_rtc_alarm_irq_enable, .alarm_irq_enable = mc13xxx_rtc_alarm_irq_enable,
...@@ -285,8 +282,15 @@ static int __init mc13xxx_rtc_probe(struct platform_device *pdev) ...@@ -285,8 +282,15 @@ static int __init mc13xxx_rtc_probe(struct platform_device *pdev)
priv->mc13xxx = mc13xxx; priv->mc13xxx = mc13xxx;
priv->valid = 1; priv->valid = 1;
priv->rtc = devm_rtc_allocate_device(&pdev->dev);
if (IS_ERR(priv->rtc))
return PTR_ERR(priv->rtc);
platform_set_drvdata(pdev, priv); platform_set_drvdata(pdev, priv);
priv->rtc->ops = &mc13xxx_rtc_ops;
/* 15bit days + hours, minutes, seconds */
priv->rtc->range_max = (timeu64_t)(1 << 15) * SEC_PER_DAY - 1;
mc13xxx_lock(mc13xxx); mc13xxx_lock(mc13xxx);
mc13xxx_irq_ack(mc13xxx, MC13XXX_IRQ_RTCRST); mc13xxx_irq_ack(mc13xxx, MC13XXX_IRQ_RTCRST);
...@@ -303,8 +307,9 @@ static int __init mc13xxx_rtc_probe(struct platform_device *pdev) ...@@ -303,8 +307,9 @@ static int __init mc13xxx_rtc_probe(struct platform_device *pdev)
mc13xxx_unlock(mc13xxx); mc13xxx_unlock(mc13xxx);
priv->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, ret = rtc_register_device(priv->rtc);
&mc13xxx_rtc_ops, THIS_MODULE); if (ret)
goto err_irq_request;
return 0; return 0;
......
...@@ -343,7 +343,7 @@ static int mtk_rtc_probe(struct platform_device *pdev) ...@@ -343,7 +343,7 @@ static int mtk_rtc_probe(struct platform_device *pdev)
if (ret) { if (ret) {
dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n", dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n",
rtc->irq, ret); rtc->irq, ret);
goto out_dispose_irq; return ret;
} }
device_init_wakeup(&pdev->dev, 1); device_init_wakeup(&pdev->dev, 1);
...@@ -359,9 +359,7 @@ static int mtk_rtc_probe(struct platform_device *pdev) ...@@ -359,9 +359,7 @@ static int mtk_rtc_probe(struct platform_device *pdev)
return 0; return 0;
out_free_irq: out_free_irq:
free_irq(rtc->irq, rtc->rtc_dev); free_irq(rtc->irq, rtc);
out_dispose_irq:
irq_dispose_mapping(rtc->irq);
return ret; return ret;
} }
...@@ -369,8 +367,7 @@ static int mtk_rtc_remove(struct platform_device *pdev) ...@@ -369,8 +367,7 @@ static int mtk_rtc_remove(struct platform_device *pdev)
{ {
struct mt6397_rtc *rtc = platform_get_drvdata(pdev); struct mt6397_rtc *rtc = platform_get_drvdata(pdev);
free_irq(rtc->irq, rtc->rtc_dev); free_irq(rtc->irq, rtc);
irq_dispose_mapping(rtc->irq);
return 0; return 0;
} }
......
// SPDX-License-Identifier: GPL-2.0
/* /*
* Driver for the RTC in Marvell SoCs. * Driver for the RTC in Marvell SoCs.
*
* This file is licensed under the terms of the GNU General Public
* License version 2. This program is licensed "as is" without any
* warranty of any kind, whether express or implied.
*/ */
#include <linux/init.h> #include <linux/init.h>
...@@ -60,7 +57,7 @@ static int mv_rtc_set_time(struct device *dev, struct rtc_time *tm) ...@@ -60,7 +57,7 @@ static int mv_rtc_set_time(struct device *dev, struct rtc_time *tm)
rtc_reg = (bin2bcd(tm->tm_mday) << RTC_MDAY_OFFS) | rtc_reg = (bin2bcd(tm->tm_mday) << RTC_MDAY_OFFS) |
(bin2bcd(tm->tm_mon + 1) << RTC_MONTH_OFFS) | (bin2bcd(tm->tm_mon + 1) << RTC_MONTH_OFFS) |
(bin2bcd(tm->tm_year % 100) << RTC_YEAR_OFFS); (bin2bcd(tm->tm_year - 100) << RTC_YEAR_OFFS);
writel(rtc_reg, ioaddr + RTC_DATE_REG_OFFS); writel(rtc_reg, ioaddr + RTC_DATE_REG_OFFS);
return 0; return 0;
...@@ -159,7 +156,7 @@ static int mv_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm) ...@@ -159,7 +156,7 @@ static int mv_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
<< RTC_MONTH_OFFS; << RTC_MONTH_OFFS;
if (alm->time.tm_year >= 0) if (alm->time.tm_year >= 0)
rtc_reg |= (RTC_ALARM_VALID | bin2bcd(alm->time.tm_year % 100)) rtc_reg |= (RTC_ALARM_VALID | bin2bcd(alm->time.tm_year - 100))
<< RTC_YEAR_OFFS; << RTC_YEAR_OFFS;
writel(rtc_reg, ioaddr + RTC_ALARM_DATE_REG_OFFS); writel(rtc_reg, ioaddr + RTC_ALARM_DATE_REG_OFFS);
...@@ -257,15 +254,7 @@ static int __init mv_rtc_probe(struct platform_device *pdev) ...@@ -257,15 +254,7 @@ static int __init mv_rtc_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, pdata); platform_set_drvdata(pdev, pdata);
if (pdata->irq >= 0) { pdata->rtc = devm_rtc_allocate_device(&pdev->dev);
device_init_wakeup(&pdev->dev, 1);
pdata->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
&mv_rtc_alarm_ops,
THIS_MODULE);
} else {
pdata->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
&mv_rtc_ops, THIS_MODULE);
}
if (IS_ERR(pdata->rtc)) { if (IS_ERR(pdata->rtc)) {
ret = PTR_ERR(pdata->rtc); ret = PTR_ERR(pdata->rtc);
goto out; goto out;
...@@ -281,7 +270,19 @@ static int __init mv_rtc_probe(struct platform_device *pdev) ...@@ -281,7 +270,19 @@ static int __init mv_rtc_probe(struct platform_device *pdev)
} }
} }
return 0; if (pdata->irq >= 0) {
device_init_wakeup(&pdev->dev, 1);
pdata->rtc->ops = &mv_rtc_alarm_ops;
} else {
pdata->rtc->ops = &mv_rtc_ops;
}
pdata->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
pdata->rtc->range_max = RTC_TIMESTAMP_END_2099;
ret = rtc_register_device(pdata->rtc);
if (!ret)
return 0;
out: out:
if (!IS_ERR(pdata->clk)) if (!IS_ERR(pdata->clk))
clk_disable_unprepare(pdata->clk); clk_disable_unprepare(pdata->clk);
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/pm_wakeirq.h>
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/of_device.h> #include <linux/of_device.h>
...@@ -253,20 +254,9 @@ static int mxc_rtc_read_time(struct device *dev, struct rtc_time *tm) ...@@ -253,20 +254,9 @@ static int mxc_rtc_read_time(struct device *dev, struct rtc_time *tm)
/* /*
* This function sets the internal RTC time based on tm in Gregorian date. * This function sets the internal RTC time based on tm in Gregorian date.
*/ */
static int mxc_rtc_set_mmss(struct device *dev, time64_t time) static int mxc_rtc_set_time(struct device *dev, struct rtc_time *tm)
{ {
struct rtc_plat_data *pdata = dev_get_drvdata(dev); time64_t time = rtc_tm_to_time64(tm);
/*
* TTC_DAYR register is 9-bit in MX1 SoC, save time and day of year only
*/
if (is_imx1_rtc(pdata)) {
struct rtc_time tm;
rtc_time64_to_tm(time, &tm);
tm.tm_year = 70;
time = rtc_tm_to_time64(&tm);
}
/* Avoid roll-over from reading the different registers */ /* Avoid roll-over from reading the different registers */
do { do {
...@@ -310,7 +300,7 @@ static int mxc_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) ...@@ -310,7 +300,7 @@ static int mxc_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
/* RTC layer */ /* RTC layer */
static const struct rtc_class_ops mxc_rtc_ops = { static const struct rtc_class_ops mxc_rtc_ops = {
.read_time = mxc_rtc_read_time, .read_time = mxc_rtc_read_time,
.set_mmss64 = mxc_rtc_set_mmss, .set_time = mxc_rtc_set_time,
.read_alarm = mxc_rtc_read_alarm, .read_alarm = mxc_rtc_read_alarm,
.set_alarm = mxc_rtc_set_alarm, .set_alarm = mxc_rtc_set_alarm,
.alarm_irq_enable = mxc_rtc_alarm_irq_enable, .alarm_irq_enable = mxc_rtc_alarm_irq_enable,
...@@ -318,7 +308,6 @@ static const struct rtc_class_ops mxc_rtc_ops = { ...@@ -318,7 +308,6 @@ static const struct rtc_class_ops mxc_rtc_ops = {
static int mxc_rtc_probe(struct platform_device *pdev) static int mxc_rtc_probe(struct platform_device *pdev)
{ {
struct resource *res;
struct rtc_device *rtc; struct rtc_device *rtc;
struct rtc_plat_data *pdata = NULL; struct rtc_plat_data *pdata = NULL;
u32 reg; u32 reg;
...@@ -336,11 +325,34 @@ static int mxc_rtc_probe(struct platform_device *pdev) ...@@ -336,11 +325,34 @@ static int mxc_rtc_probe(struct platform_device *pdev)
else else
pdata->devtype = pdev->id_entry->driver_data; pdata->devtype = pdev->id_entry->driver_data;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); pdata->ioaddr = devm_platform_ioremap_resource(pdev, 0);
pdata->ioaddr = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(pdata->ioaddr)) if (IS_ERR(pdata->ioaddr))
return PTR_ERR(pdata->ioaddr); return PTR_ERR(pdata->ioaddr);
rtc = devm_rtc_allocate_device(&pdev->dev);
if (IS_ERR(rtc))
return PTR_ERR(rtc);
pdata->rtc = rtc;
rtc->ops = &mxc_rtc_ops;
if (is_imx1_rtc(pdata)) {
struct rtc_time tm;
/* 9bit days + hours minutes seconds */
rtc->range_max = (1 << 9) * 86400 - 1;
/*
* Set the start date as beginning of the current year. This can
* be overridden using device tree.
*/
rtc_time64_to_tm(ktime_get_real_seconds(), &tm);
rtc->start_secs = mktime64(tm.tm_year, 1, 1, 0, 0, 0);
rtc->set_start_time = true;
} else {
/* 16bit days + hours minutes seconds */
rtc->range_max = (1 << 16) * 86400ULL - 1;
}
pdata->clk_ipg = devm_clk_get(&pdev->dev, "ipg"); pdata->clk_ipg = devm_clk_get(&pdev->dev, "ipg");
if (IS_ERR(pdata->clk_ipg)) { if (IS_ERR(pdata->clk_ipg)) {
dev_err(&pdev->dev, "unable to get ipg clock!\n"); dev_err(&pdev->dev, "unable to get ipg clock!\n");
...@@ -396,17 +408,16 @@ static int mxc_rtc_probe(struct platform_device *pdev) ...@@ -396,17 +408,16 @@ static int mxc_rtc_probe(struct platform_device *pdev)
pdata->irq = -1; pdata->irq = -1;
} }
if (pdata->irq >= 0) if (pdata->irq >= 0) {
device_init_wakeup(&pdev->dev, 1); device_init_wakeup(&pdev->dev, 1);
ret = dev_pm_set_wake_irq(&pdev->dev, pdata->irq);
rtc = devm_rtc_device_register(&pdev->dev, pdev->name, &mxc_rtc_ops, if (ret)
THIS_MODULE); dev_err(&pdev->dev, "failed to enable irq wake\n");
if (IS_ERR(rtc)) {
ret = PTR_ERR(rtc);
goto exit_put_clk_ref;
} }
pdata->rtc = rtc; ret = rtc_register_device(rtc);
if (ret)
goto exit_put_clk_ref;
return 0; return 0;
...@@ -428,35 +439,10 @@ static int mxc_rtc_remove(struct platform_device *pdev) ...@@ -428,35 +439,10 @@ static int mxc_rtc_remove(struct platform_device *pdev)
return 0; return 0;
} }
#ifdef CONFIG_PM_SLEEP
static int mxc_rtc_suspend(struct device *dev)
{
struct rtc_plat_data *pdata = dev_get_drvdata(dev);
if (device_may_wakeup(dev))
enable_irq_wake(pdata->irq);
return 0;
}
static int mxc_rtc_resume(struct device *dev)
{
struct rtc_plat_data *pdata = dev_get_drvdata(dev);
if (device_may_wakeup(dev))
disable_irq_wake(pdata->irq);
return 0;
}
#endif
static SIMPLE_DEV_PM_OPS(mxc_rtc_pm_ops, mxc_rtc_suspend, mxc_rtc_resume);
static struct platform_driver mxc_rtc_driver = { static struct platform_driver mxc_rtc_driver = {
.driver = { .driver = {
.name = "mxc_rtc", .name = "mxc_rtc",
.of_match_table = of_match_ptr(imx_rtc_dt_ids), .of_match_table = of_match_ptr(imx_rtc_dt_ids),
.pm = &mxc_rtc_pm_ops,
}, },
.id_table = imx_rtc_devtype, .id_table = imx_rtc_devtype,
.probe = mxc_rtc_probe, .probe = mxc_rtc_probe,
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/mod_devicetable.h> #include <linux/mod_devicetable.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/pm_wakeirq.h>
#include <linux/rtc.h> #include <linux/rtc.h>
#define SRTC_LPPDR_INIT 0x41736166 /* init for glitch detect */ #define SRTC_LPPDR_INIT 0x41736166 /* init for glitch detect */
...@@ -305,6 +306,9 @@ static int mxc_rtc_probe(struct platform_device *pdev) ...@@ -305,6 +306,9 @@ static int mxc_rtc_probe(struct platform_device *pdev)
return pdata->irq; return pdata->irq;
device_init_wakeup(&pdev->dev, 1); device_init_wakeup(&pdev->dev, 1);
ret = dev_pm_set_wake_irq(&pdev->dev, pdata->irq);
if (ret)
dev_err(&pdev->dev, "failed to enable irq wake\n");
ret = clk_prepare_enable(pdata->clk); ret = clk_prepare_enable(pdata->clk);
if (ret) if (ret)
...@@ -367,30 +371,6 @@ static int mxc_rtc_remove(struct platform_device *pdev) ...@@ -367,30 +371,6 @@ static int mxc_rtc_remove(struct platform_device *pdev)
return 0; return 0;
} }
#ifdef CONFIG_PM_SLEEP
static int mxc_rtc_suspend(struct device *dev)
{
struct mxc_rtc_data *pdata = dev_get_drvdata(dev);
if (device_may_wakeup(dev))
enable_irq_wake(pdata->irq);
return 0;
}
static int mxc_rtc_resume(struct device *dev)
{
struct mxc_rtc_data *pdata = dev_get_drvdata(dev);
if (device_may_wakeup(dev))
disable_irq_wake(pdata->irq);
return 0;
}
#endif
static SIMPLE_DEV_PM_OPS(mxc_rtc_pm_ops, mxc_rtc_suspend, mxc_rtc_resume);
static const struct of_device_id mxc_ids[] = { static const struct of_device_id mxc_ids[] = {
{ .compatible = "fsl,imx53-rtc", }, { .compatible = "fsl,imx53-rtc", },
{} {}
...@@ -400,7 +380,6 @@ static struct platform_driver mxc_rtc_driver = { ...@@ -400,7 +380,6 @@ static struct platform_driver mxc_rtc_driver = {
.driver = { .driver = {
.name = "mxc_rtc_v2", .name = "mxc_rtc_v2",
.of_match_table = mxc_ids, .of_match_table = mxc_ids,
.pm = &mxc_rtc_pm_ops,
}, },
.probe = mxc_rtc_probe, .probe = mxc_rtc_probe,
.remove = mxc_rtc_remove, .remove = mxc_rtc_remove,
......
// SPDX-License-Identifier: GPL-2.0+
/* /*
* TI OMAP Real Time Clock interface for Linux * TI OMAP Real Time Clock interface for Linux
* *
...@@ -6,11 +7,6 @@ ...@@ -6,11 +7,6 @@
* *
* Copyright (C) 2006 David Brownell (new RTC framework) * Copyright (C) 2006 David Brownell (new RTC framework)
* Copyright (C) 2014 Johan Hovold <johan@kernel.org> * Copyright (C) 2014 Johan Hovold <johan@kernel.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/ */
#include <dt-bindings/gpio/gpio.h> #include <dt-bindings/gpio/gpio.h>
...@@ -271,7 +267,7 @@ static int omap_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) ...@@ -271,7 +267,7 @@ static int omap_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
} }
/* this hardware doesn't support "don't care" alarm fields */ /* this hardware doesn't support "don't care" alarm fields */
static int tm2bcd(struct rtc_time *tm) static void tm2bcd(struct rtc_time *tm)
{ {
tm->tm_sec = bin2bcd(tm->tm_sec); tm->tm_sec = bin2bcd(tm->tm_sec);
tm->tm_min = bin2bcd(tm->tm_min); tm->tm_min = bin2bcd(tm->tm_min);
...@@ -279,13 +275,7 @@ static int tm2bcd(struct rtc_time *tm) ...@@ -279,13 +275,7 @@ static int tm2bcd(struct rtc_time *tm)
tm->tm_mday = bin2bcd(tm->tm_mday); tm->tm_mday = bin2bcd(tm->tm_mday);
tm->tm_mon = bin2bcd(tm->tm_mon + 1); tm->tm_mon = bin2bcd(tm->tm_mon + 1);
/* epoch == 1900 */
if (tm->tm_year < 100 || tm->tm_year > 199)
return -EINVAL;
tm->tm_year = bin2bcd(tm->tm_year - 100); tm->tm_year = bin2bcd(tm->tm_year - 100);
return 0;
} }
static void bcd2tm(struct rtc_time *tm) static void bcd2tm(struct rtc_time *tm)
...@@ -328,8 +318,7 @@ static int omap_rtc_set_time(struct device *dev, struct rtc_time *tm) ...@@ -328,8 +318,7 @@ static int omap_rtc_set_time(struct device *dev, struct rtc_time *tm)
{ {
struct omap_rtc *rtc = dev_get_drvdata(dev); struct omap_rtc *rtc = dev_get_drvdata(dev);
if (tm2bcd(tm) < 0) tm2bcd(tm);
return -EINVAL;
local_irq_disable(); local_irq_disable();
rtc_wait_not_busy(rtc); rtc_wait_not_busy(rtc);
...@@ -378,8 +367,7 @@ static int omap_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm) ...@@ -378,8 +367,7 @@ static int omap_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
struct omap_rtc *rtc = dev_get_drvdata(dev); struct omap_rtc *rtc = dev_get_drvdata(dev);
u8 reg, irqwake_reg = 0; u8 reg, irqwake_reg = 0;
if (tm2bcd(&alm->time) < 0) tm2bcd(&alm->time);
return -EINVAL;
local_irq_disable(); local_irq_disable();
rtc_wait_not_busy(rtc); rtc_wait_not_busy(rtc);
...@@ -441,14 +429,10 @@ static void omap_rtc_power_off(void) ...@@ -441,14 +429,10 @@ static void omap_rtc_power_off(void)
omap_rtc_read_time_raw(rtc, &tm); omap_rtc_read_time_raw(rtc, &tm);
seconds = tm.tm_sec; seconds = tm.tm_sec;
bcd2tm(&tm); bcd2tm(&tm);
rtc_tm_to_time(&tm, &now); now = rtc_tm_to_time64(&tm);
rtc_time_to_tm(now + 1, &tm); rtc_time64_to_tm(now + 1, &tm);
if (tm2bcd(&tm) < 0) { tm2bcd(&tm);
dev_err(&rtc->rtc->dev, "power off failed\n");
rtc->type->lock(rtc);
return;
}
rtc_wait_not_busy(rtc); rtc_wait_not_busy(rtc);
...@@ -845,6 +829,8 @@ static int omap_rtc_probe(struct platform_device *pdev) ...@@ -845,6 +829,8 @@ static int omap_rtc_probe(struct platform_device *pdev)
} }
rtc->rtc->ops = &omap_rtc_ops; rtc->rtc->ops = &omap_rtc_ops;
rtc->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
rtc->rtc->range_max = RTC_TIMESTAMP_END_2099;
omap_rtc_nvmem_config.priv = rtc; omap_rtc_nvmem_config.priv = rtc;
/* handle periodic and alarm irqs */ /* handle periodic and alarm irqs */
......
...@@ -224,7 +224,7 @@ static int opal_set_tpo_time(struct device *dev, struct rtc_wkalrm *alarm) ...@@ -224,7 +224,7 @@ static int opal_set_tpo_time(struct device *dev, struct rtc_wkalrm *alarm)
return rc; return rc;
} }
int opal_tpo_alarm_irq_enable(struct device *dev, unsigned int enabled) static int opal_tpo_alarm_irq_enable(struct device *dev, unsigned int enabled)
{ {
struct rtc_wkalrm alarm = { .enabled = 0 }; struct rtc_wkalrm alarm = { .enabled = 0 };
......
// SPDX-License-Identifier: GPL-2.0
/* /*
* pcap rtc code for Motorola EZX phones * pcap rtc code for Motorola EZX phones
* *
...@@ -5,11 +6,6 @@ ...@@ -5,11 +6,6 @@
* Copyright (c) 2009 Daniel Ribeiro <drwyrm@gmail.com> * Copyright (c) 2009 Daniel Ribeiro <drwyrm@gmail.com>
* *
* Based on Motorola's rtc.c Copyright (c) 2003-2005 Motorola * Based on Motorola's rtc.c Copyright (c) 2003-2005 Motorola
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
*/ */
#include <linux/kernel.h> #include <linux/kernel.h>
...@@ -55,7 +51,7 @@ static int pcap_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) ...@@ -55,7 +51,7 @@ static int pcap_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
ezx_pcap_read(pcap_rtc->pcap, PCAP_REG_RTC_DAYA, &days); ezx_pcap_read(pcap_rtc->pcap, PCAP_REG_RTC_DAYA, &days);
secs += (days & PCAP_RTC_DAY_MASK) * SEC_PER_DAY; secs += (days & PCAP_RTC_DAY_MASK) * SEC_PER_DAY;
rtc_time_to_tm(secs, tm); rtc_time64_to_tm(secs, tm);
return 0; return 0;
} }
...@@ -63,12 +59,9 @@ static int pcap_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) ...@@ -63,12 +59,9 @@ static int pcap_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
static int pcap_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) static int pcap_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{ {
struct pcap_rtc *pcap_rtc = dev_get_drvdata(dev); struct pcap_rtc *pcap_rtc = dev_get_drvdata(dev);
struct rtc_time *tm = &alrm->time; unsigned long secs = rtc_tm_to_time64(&alrm->time);
unsigned long secs;
u32 tod, days; u32 tod, days;
rtc_tm_to_time(tm, &secs);
tod = secs % SEC_PER_DAY; tod = secs % SEC_PER_DAY;
ezx_pcap_write(pcap_rtc->pcap, PCAP_REG_RTC_TODA, tod); ezx_pcap_write(pcap_rtc->pcap, PCAP_REG_RTC_TODA, tod);
...@@ -90,14 +83,15 @@ static int pcap_rtc_read_time(struct device *dev, struct rtc_time *tm) ...@@ -90,14 +83,15 @@ static int pcap_rtc_read_time(struct device *dev, struct rtc_time *tm)
ezx_pcap_read(pcap_rtc->pcap, PCAP_REG_RTC_DAY, &days); ezx_pcap_read(pcap_rtc->pcap, PCAP_REG_RTC_DAY, &days);
secs += (days & PCAP_RTC_DAY_MASK) * SEC_PER_DAY; secs += (days & PCAP_RTC_DAY_MASK) * SEC_PER_DAY;
rtc_time_to_tm(secs, tm); rtc_time64_to_tm(secs, tm);
return 0; return 0;
} }
static int pcap_rtc_set_mmss(struct device *dev, unsigned long secs) static int pcap_rtc_set_time(struct device *dev, struct rtc_time *tm)
{ {
struct pcap_rtc *pcap_rtc = dev_get_drvdata(dev); struct pcap_rtc *pcap_rtc = dev_get_drvdata(dev);
unsigned long secs = rtc_tm_to_time64(tm);
u32 tod, days; u32 tod, days;
tod = secs % SEC_PER_DAY; tod = secs % SEC_PER_DAY;
...@@ -128,9 +122,9 @@ static int pcap_rtc_alarm_irq_enable(struct device *dev, unsigned int en) ...@@ -128,9 +122,9 @@ static int pcap_rtc_alarm_irq_enable(struct device *dev, unsigned int en)
static const struct rtc_class_ops pcap_rtc_ops = { static const struct rtc_class_ops pcap_rtc_ops = {
.read_time = pcap_rtc_read_time, .read_time = pcap_rtc_read_time,
.set_time = pcap_rtc_set_time,
.read_alarm = pcap_rtc_read_alarm, .read_alarm = pcap_rtc_read_alarm,
.set_alarm = pcap_rtc_set_alarm, .set_alarm = pcap_rtc_set_alarm,
.set_mmss = pcap_rtc_set_mmss,
.alarm_irq_enable = pcap_rtc_alarm_irq_enable, .alarm_irq_enable = pcap_rtc_alarm_irq_enable,
}; };
...@@ -149,11 +143,13 @@ static int __init pcap_rtc_probe(struct platform_device *pdev) ...@@ -149,11 +143,13 @@ static int __init pcap_rtc_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, pcap_rtc); platform_set_drvdata(pdev, pcap_rtc);
pcap_rtc->rtc = devm_rtc_device_register(&pdev->dev, "pcap", pcap_rtc->rtc = devm_rtc_allocate_device(&pdev->dev);
&pcap_rtc_ops, THIS_MODULE);
if (IS_ERR(pcap_rtc->rtc)) if (IS_ERR(pcap_rtc->rtc))
return PTR_ERR(pcap_rtc->rtc); return PTR_ERR(pcap_rtc->rtc);
pcap_rtc->rtc->ops = &pcap_rtc_ops;
pcap_rtc->rtc->range_max = (1 << 14) * 86400ULL - 1;
timer_irq = pcap_to_irq(pcap_rtc->pcap, PCAP_IRQ_1HZ); timer_irq = pcap_to_irq(pcap_rtc->pcap, PCAP_IRQ_1HZ);
alarm_irq = pcap_to_irq(pcap_rtc->pcap, PCAP_IRQ_TODA); alarm_irq = pcap_to_irq(pcap_rtc->pcap, PCAP_IRQ_TODA);
...@@ -167,7 +163,7 @@ static int __init pcap_rtc_probe(struct platform_device *pdev) ...@@ -167,7 +163,7 @@ static int __init pcap_rtc_probe(struct platform_device *pdev)
if (err) if (err)
return err; return err;
return 0; return rtc_register_device(pcap_rtc->rtc);
} }
static int __exit pcap_rtc_remove(struct platform_device *pdev) static int __exit pcap_rtc_remove(struct platform_device *pdev)
......
// SPDX-License-Identifier: GPL-2.0
/* /*
* An I2C driver for the PCF85063 RTC * An I2C driver for the PCF85063 RTC
* Copyright 2014 Rose Technology * Copyright 2014 Rose Technology
...@@ -5,16 +6,16 @@ ...@@ -5,16 +6,16 @@
* Author: Søren Andersen <san@rosetechnology.dk> * Author: Søren Andersen <san@rosetechnology.dk>
* Maintainers: http://www.nslu2-linux.org/ * Maintainers: http://www.nslu2-linux.org/
* *
* based on the other drivers in this same directory. * Copyright (C) 2019 Micro Crystal AG
* * Author: Alexandre Belloni <alexandre.belloni@bootlin.com>
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/ */
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/bcd.h> #include <linux/bcd.h>
#include <linux/rtc.h> #include <linux/rtc.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/of_device.h>
#include <linux/pm_wakeirq.h>
#include <linux/regmap.h>
/* /*
* Information for this driver was pulled from the following datasheets. * Information for this driver was pulled from the following datasheets.
...@@ -24,61 +25,47 @@ ...@@ -24,61 +25,47 @@
* *
* PCF85063A -- Rev. 6 — 18 November 2015 * PCF85063A -- Rev. 6 — 18 November 2015
* PCF85063TP -- Rev. 4 — 6 May 2015 * PCF85063TP -- Rev. 4 — 6 May 2015
*/ *
* https://www.microcrystal.com/fileadmin/Media/Products/RTC/App.Manual/RV-8263-C7_App-Manual.pdf
* RV8263 -- Rev. 1.0 — January 2019
*/
#define PCF85063_REG_CTRL1 0x00 /* status */ #define PCF85063_REG_CTRL1 0x00 /* status */
#define PCF85063_REG_CTRL1_CAP_SEL BIT(0) #define PCF85063_REG_CTRL1_CAP_SEL BIT(0)
#define PCF85063_REG_CTRL1_STOP BIT(5) #define PCF85063_REG_CTRL1_STOP BIT(5)
#define PCF85063_REG_SC 0x04 /* datetime */ #define PCF85063_REG_CTRL2 0x01
#define PCF85063_REG_SC_OS 0x80 #define PCF85063_CTRL2_AF BIT(6)
#define PCF85063_CTRL2_AIE BIT(7)
static struct i2c_driver pcf85063_driver;
static int pcf85063_stop_clock(struct i2c_client *client, u8 *ctrl1)
{
int rc;
u8 reg;
rc = i2c_smbus_read_byte_data(client, PCF85063_REG_CTRL1); #define PCF85063_REG_OFFSET 0x02
if (rc < 0) { #define PCF85063_OFFSET_SIGN_BIT 6 /* 2's complement sign bit */
dev_err(&client->dev, "Failing to stop the clock\n"); #define PCF85063_OFFSET_MODE BIT(7)
return -EIO; #define PCF85063_OFFSET_STEP0 4340
} #define PCF85063_OFFSET_STEP1 4069
/* stop the clock */ #define PCF85063_REG_RAM 0x03
reg = rc | PCF85063_REG_CTRL1_STOP;
rc = i2c_smbus_write_byte_data(client, PCF85063_REG_CTRL1, reg); #define PCF85063_REG_SC 0x04 /* datetime */
if (rc < 0) { #define PCF85063_REG_SC_OS 0x80
dev_err(&client->dev, "Failing to stop the clock\n");
return -EIO;
}
*ctrl1 = reg;
return 0;
}
static int pcf85063_start_clock(struct i2c_client *client, u8 ctrl1)
{
int rc;
/* start the clock */ #define PCF85063_REG_ALM_S 0x0b
ctrl1 &= ~PCF85063_REG_CTRL1_STOP; #define PCF85063_AEN BIT(7)
rc = i2c_smbus_write_byte_data(client, PCF85063_REG_CTRL1, ctrl1); struct pcf85063_config {
if (rc < 0) { struct regmap_config regmap;
dev_err(&client->dev, "Failing to start the clock\n"); unsigned has_alarms:1;
return -EIO; unsigned force_cap_7000:1;
} };
return 0; struct pcf85063 {
} struct rtc_device *rtc;
struct regmap *regmap;
};
static int pcf85063_rtc_read_time(struct device *dev, struct rtc_time *tm) static int pcf85063_rtc_read_time(struct device *dev, struct rtc_time *tm)
{ {
struct i2c_client *client = to_i2c_client(dev); struct pcf85063 *pcf85063 = dev_get_drvdata(dev);
int rc; int rc;
u8 regs[7]; u8 regs[7];
...@@ -88,16 +75,14 @@ static int pcf85063_rtc_read_time(struct device *dev, struct rtc_time *tm) ...@@ -88,16 +75,14 @@ static int pcf85063_rtc_read_time(struct device *dev, struct rtc_time *tm)
* event, the access must be finished within one second. So, read all * event, the access must be finished within one second. So, read all
* time/date registers in one turn. * time/date registers in one turn.
*/ */
rc = i2c_smbus_read_i2c_block_data(client, PCF85063_REG_SC, rc = regmap_bulk_read(pcf85063->regmap, PCF85063_REG_SC, regs,
sizeof(regs), regs); sizeof(regs));
if (rc != sizeof(regs)) { if (rc)
dev_err(&client->dev, "date/time register read error\n"); return rc;
return -EIO;
}
/* if the clock has lost its power it makes no sense to use its time */ /* if the clock has lost its power it makes no sense to use its time */
if (regs[0] & PCF85063_REG_SC_OS) { if (regs[0] & PCF85063_REG_SC_OS) {
dev_warn(&client->dev, "Power loss detected, invalid time\n"); dev_warn(&pcf85063->rtc->dev, "Power loss detected, invalid time\n");
return -EINVAL; return -EINVAL;
} }
...@@ -115,20 +100,18 @@ static int pcf85063_rtc_read_time(struct device *dev, struct rtc_time *tm) ...@@ -115,20 +100,18 @@ static int pcf85063_rtc_read_time(struct device *dev, struct rtc_time *tm)
static int pcf85063_rtc_set_time(struct device *dev, struct rtc_time *tm) static int pcf85063_rtc_set_time(struct device *dev, struct rtc_time *tm)
{ {
struct i2c_client *client = to_i2c_client(dev); struct pcf85063 *pcf85063 = dev_get_drvdata(dev);
int rc; int rc;
u8 regs[7]; u8 regs[7];
u8 ctrl1;
if ((tm->tm_year < 100) || (tm->tm_year > 199))
return -EINVAL;
/* /*
* to accurately set the time, reset the divider chain and keep it in * to accurately set the time, reset the divider chain and keep it in
* reset state until all time/date registers are written * reset state until all time/date registers are written
*/ */
rc = pcf85063_stop_clock(client, &ctrl1); rc = regmap_update_bits(pcf85063->regmap, PCF85063_REG_CTRL1,
if (rc != 0) PCF85063_REG_CTRL1_STOP,
PCF85063_REG_CTRL1_STOP);
if (rc)
return rc; return rc;
/* hours, minutes and seconds */ /* hours, minutes and seconds */
...@@ -150,101 +133,351 @@ static int pcf85063_rtc_set_time(struct device *dev, struct rtc_time *tm) ...@@ -150,101 +133,351 @@ static int pcf85063_rtc_set_time(struct device *dev, struct rtc_time *tm)
regs[6] = bin2bcd(tm->tm_year - 100); regs[6] = bin2bcd(tm->tm_year - 100);
/* write all registers at once */ /* write all registers at once */
rc = i2c_smbus_write_i2c_block_data(client, PCF85063_REG_SC, rc = regmap_bulk_write(pcf85063->regmap, PCF85063_REG_SC,
sizeof(regs), regs); regs, sizeof(regs));
if (rc < 0) { if (rc)
dev_err(&client->dev, "date/time register write error\n");
return rc; return rc;
}
/* /*
* Write the control register as a separate action since the size of * Write the control register as a separate action since the size of
* the register space is different between the PCF85063TP and * the register space is different between the PCF85063TP and
* PCF85063A devices. The rollover point can not be used. * PCF85063A devices. The rollover point can not be used.
*/ */
rc = pcf85063_start_clock(client, ctrl1); return regmap_update_bits(pcf85063->regmap, PCF85063_REG_CTRL1,
if (rc != 0) PCF85063_REG_CTRL1_STOP, 0);
return rc; }
static int pcf85063_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{
struct pcf85063 *pcf85063 = dev_get_drvdata(dev);
u8 buf[4];
unsigned int val;
int ret;
ret = regmap_bulk_read(pcf85063->regmap, PCF85063_REG_ALM_S,
buf, sizeof(buf));
if (ret)
return ret;
alrm->time.tm_sec = bcd2bin(buf[0]);
alrm->time.tm_min = bcd2bin(buf[1]);
alrm->time.tm_hour = bcd2bin(buf[2]);
alrm->time.tm_mday = bcd2bin(buf[3]);
ret = regmap_read(pcf85063->regmap, PCF85063_REG_CTRL2, &val);
if (ret)
return ret;
alrm->enabled = !!(val & PCF85063_CTRL2_AIE);
return 0; return 0;
} }
static int pcf85063_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{
struct pcf85063 *pcf85063 = dev_get_drvdata(dev);
u8 buf[5];
int ret;
buf[0] = bin2bcd(alrm->time.tm_sec);
buf[1] = bin2bcd(alrm->time.tm_min);
buf[2] = bin2bcd(alrm->time.tm_hour);
buf[3] = bin2bcd(alrm->time.tm_mday);
buf[4] = PCF85063_AEN; /* Do not match on week day */
ret = regmap_update_bits(pcf85063->regmap, PCF85063_REG_CTRL2,
PCF85063_CTRL2_AIE | PCF85063_CTRL2_AF, 0);
if (ret)
return ret;
ret = regmap_bulk_write(pcf85063->regmap, PCF85063_REG_ALM_S,
buf, sizeof(buf));
if (ret)
return ret;
return regmap_update_bits(pcf85063->regmap, PCF85063_REG_CTRL2,
PCF85063_CTRL2_AIE | PCF85063_CTRL2_AF,
alrm->enabled ? PCF85063_CTRL2_AIE | PCF85063_CTRL2_AF : PCF85063_CTRL2_AF);
}
static int pcf85063_rtc_alarm_irq_enable(struct device *dev,
unsigned int enabled)
{
struct pcf85063 *pcf85063 = dev_get_drvdata(dev);
return regmap_update_bits(pcf85063->regmap, PCF85063_REG_CTRL2,
PCF85063_CTRL2_AIE,
enabled ? PCF85063_CTRL2_AIE : 0);
}
static irqreturn_t pcf85063_rtc_handle_irq(int irq, void *dev_id)
{
struct pcf85063 *pcf85063 = dev_id;
unsigned int val;
int err;
err = regmap_read(pcf85063->regmap, PCF85063_REG_CTRL2, &val);
if (err)
return IRQ_NONE;
if (val & PCF85063_CTRL2_AF) {
rtc_update_irq(pcf85063->rtc, 1, RTC_IRQF | RTC_AF);
regmap_update_bits(pcf85063->regmap, PCF85063_REG_CTRL2,
PCF85063_CTRL2_AIE | PCF85063_CTRL2_AF,
0);
return IRQ_HANDLED;
}
return IRQ_NONE;
}
static int pcf85063_read_offset(struct device *dev, long *offset)
{
struct pcf85063 *pcf85063 = dev_get_drvdata(dev);
long val;
u32 reg;
int ret;
ret = regmap_read(pcf85063->regmap, PCF85063_REG_OFFSET, &reg);
if (ret < 0)
return ret;
val = sign_extend32(reg & ~PCF85063_OFFSET_MODE,
PCF85063_OFFSET_SIGN_BIT);
if (reg & PCF85063_OFFSET_MODE)
*offset = val * PCF85063_OFFSET_STEP1;
else
*offset = val * PCF85063_OFFSET_STEP0;
return 0;
}
static int pcf85063_set_offset(struct device *dev, long offset)
{
struct pcf85063 *pcf85063 = dev_get_drvdata(dev);
s8 mode0, mode1, reg;
unsigned int error0, error1;
if (offset > PCF85063_OFFSET_STEP0 * 63)
return -ERANGE;
if (offset < PCF85063_OFFSET_STEP0 * -64)
return -ERANGE;
mode0 = DIV_ROUND_CLOSEST(offset, PCF85063_OFFSET_STEP0);
mode1 = DIV_ROUND_CLOSEST(offset, PCF85063_OFFSET_STEP1);
error0 = abs(offset - (mode0 * PCF85063_OFFSET_STEP0));
error1 = abs(offset - (mode1 * PCF85063_OFFSET_STEP1));
if (mode1 > 63 || mode1 < -64 || error0 < error1)
reg = mode0 & ~PCF85063_OFFSET_MODE;
else
reg = mode1 | PCF85063_OFFSET_MODE;
return regmap_write(pcf85063->regmap, PCF85063_REG_OFFSET, reg);
}
static int pcf85063_ioctl(struct device *dev, unsigned int cmd,
unsigned long arg)
{
struct pcf85063 *pcf85063 = dev_get_drvdata(dev);
int status, ret = 0;
switch (cmd) {
case RTC_VL_READ:
ret = regmap_read(pcf85063->regmap, PCF85063_REG_SC, &status);
if (ret < 0)
return ret;
if (status & PCF85063_REG_SC_OS)
dev_warn(&pcf85063->rtc->dev, "Voltage low, data loss detected.\n");
status &= PCF85063_REG_SC_OS;
if (copy_to_user((void __user *)arg, &status, sizeof(int)))
return -EFAULT;
return 0;
case RTC_VL_CLR:
ret = regmap_update_bits(pcf85063->regmap, PCF85063_REG_SC,
PCF85063_REG_SC_OS, 0);
return ret;
default:
return -ENOIOCTLCMD;
}
}
static const struct rtc_class_ops pcf85063_rtc_ops = { static const struct rtc_class_ops pcf85063_rtc_ops = {
.read_time = pcf85063_rtc_read_time, .read_time = pcf85063_rtc_read_time,
.set_time = pcf85063_rtc_set_time .set_time = pcf85063_rtc_set_time,
.read_offset = pcf85063_read_offset,
.set_offset = pcf85063_set_offset,
.ioctl = pcf85063_ioctl,
};
static const struct rtc_class_ops pcf85063_rtc_ops_alarm = {
.read_time = pcf85063_rtc_read_time,
.set_time = pcf85063_rtc_set_time,
.read_offset = pcf85063_read_offset,
.set_offset = pcf85063_set_offset,
.read_alarm = pcf85063_rtc_read_alarm,
.set_alarm = pcf85063_rtc_set_alarm,
.alarm_irq_enable = pcf85063_rtc_alarm_irq_enable,
.ioctl = pcf85063_ioctl,
}; };
static int pcf85063_load_capacitance(struct i2c_client *client) static int pcf85063_nvmem_read(void *priv, unsigned int offset,
void *val, size_t bytes)
{ {
u32 load; return regmap_read(priv, PCF85063_REG_RAM, val);
int rc; }
u8 reg;
rc = i2c_smbus_read_byte_data(client, PCF85063_REG_CTRL1); static int pcf85063_nvmem_write(void *priv, unsigned int offset,
if (rc < 0) void *val, size_t bytes)
return rc; {
return regmap_write(priv, PCF85063_REG_RAM, *(u8 *)val);
}
reg = rc; static int pcf85063_load_capacitance(struct pcf85063 *pcf85063,
load = 7000; const struct device_node *np,
of_property_read_u32(client->dev.of_node, "quartz-load-femtofarads", unsigned int force_cap)
&load); {
u32 load = 7000;
u8 reg = 0;
if (force_cap)
load = force_cap;
else
of_property_read_u32(np, "quartz-load-femtofarads", &load);
switch (load) { switch (load) {
default: default:
dev_warn(&client->dev, "Unknown quartz-load-femtofarads value: %d. Assuming 7000", dev_warn(&pcf85063->rtc->dev, "Unknown quartz-load-femtofarads value: %d. Assuming 7000",
load); load);
/* fall through */ /* fall through */
case 7000: case 7000:
reg &= ~PCF85063_REG_CTRL1_CAP_SEL;
break; break;
case 12500: case 12500:
reg |= PCF85063_REG_CTRL1_CAP_SEL; reg = PCF85063_REG_CTRL1_CAP_SEL;
break; break;
} }
rc = i2c_smbus_write_byte_data(client, PCF85063_REG_CTRL1, reg); return regmap_update_bits(pcf85063->regmap, PCF85063_REG_CTRL1,
PCF85063_REG_CTRL1_CAP_SEL, reg);
return rc;
} }
static int pcf85063_probe(struct i2c_client *client, static const struct pcf85063_config pcf85063a_config = {
const struct i2c_device_id *id) .regmap = {
.reg_bits = 8,
.val_bits = 8,
.max_register = 0x11,
},
.has_alarms = 1,
};
static const struct pcf85063_config pcf85063tp_config = {
.regmap = {
.reg_bits = 8,
.val_bits = 8,
.max_register = 0x0a,
},
};
static const struct pcf85063_config rv8263_config = {
.regmap = {
.reg_bits = 8,
.val_bits = 8,
.max_register = 0x11,
},
.has_alarms = 1,
.force_cap_7000 = 1,
};
static int pcf85063_probe(struct i2c_client *client)
{ {
struct rtc_device *rtc; struct pcf85063 *pcf85063;
unsigned int tmp;
int err; int err;
const struct pcf85063_config *config = &pcf85063tp_config;
const void *data = of_device_get_match_data(&client->dev);
struct nvmem_config nvmem_cfg = {
.name = "pcf85063_nvram",
.reg_read = pcf85063_nvmem_read,
.reg_write = pcf85063_nvmem_write,
.type = NVMEM_TYPE_BATTERY_BACKED,
.size = 1,
};
dev_dbg(&client->dev, "%s\n", __func__); dev_dbg(&client->dev, "%s\n", __func__);
if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) pcf85063 = devm_kzalloc(&client->dev, sizeof(struct pcf85063),
return -ENODEV; GFP_KERNEL);
if (!pcf85063)
return -ENOMEM;
if (data)
config = data;
pcf85063->regmap = devm_regmap_init_i2c(client, &config->regmap);
if (IS_ERR(pcf85063->regmap))
return PTR_ERR(pcf85063->regmap);
err = i2c_smbus_read_byte_data(client, PCF85063_REG_CTRL1); i2c_set_clientdata(client, pcf85063);
if (err < 0) {
err = regmap_read(pcf85063->regmap, PCF85063_REG_CTRL1, &tmp);
if (err) {
dev_err(&client->dev, "RTC chip is not present\n"); dev_err(&client->dev, "RTC chip is not present\n");
return err; return err;
} }
err = pcf85063_load_capacitance(client); pcf85063->rtc = devm_rtc_allocate_device(&client->dev);
if (IS_ERR(pcf85063->rtc))
return PTR_ERR(pcf85063->rtc);
err = pcf85063_load_capacitance(pcf85063, client->dev.of_node,
config->force_cap_7000 ? 7000 : 0);
if (err < 0) if (err < 0)
dev_warn(&client->dev, "failed to set xtal load capacitance: %d", dev_warn(&client->dev, "failed to set xtal load capacitance: %d",
err); err);
rtc = devm_rtc_device_register(&client->dev, pcf85063->rtc->ops = &pcf85063_rtc_ops;
pcf85063_driver.driver.name, pcf85063->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
&pcf85063_rtc_ops, THIS_MODULE); pcf85063->rtc->range_max = RTC_TIMESTAMP_END_2099;
pcf85063->rtc->uie_unsupported = 1;
if (config->has_alarms && client->irq > 0) {
err = devm_request_threaded_irq(&client->dev, client->irq,
NULL, pcf85063_rtc_handle_irq,
IRQF_TRIGGER_LOW | IRQF_ONESHOT,
"pcf85063", pcf85063);
if (err) {
dev_warn(&pcf85063->rtc->dev,
"unable to request IRQ, alarms disabled\n");
} else {
pcf85063->rtc->ops = &pcf85063_rtc_ops_alarm;
device_init_wakeup(&client->dev, true);
err = dev_pm_set_wake_irq(&client->dev, client->irq);
if (err)
dev_err(&pcf85063->rtc->dev,
"failed to enable irq wake\n");
}
}
nvmem_cfg.priv = pcf85063->regmap;
rtc_nvmem_register(pcf85063->rtc, &nvmem_cfg);
return PTR_ERR_OR_ZERO(rtc); return rtc_register_device(pcf85063->rtc);
} }
static const struct i2c_device_id pcf85063_id[] = {
{ "pcf85063", 0 },
{ }
};
MODULE_DEVICE_TABLE(i2c, pcf85063_id);
#ifdef CONFIG_OF #ifdef CONFIG_OF
static const struct of_device_id pcf85063_of_match[] = { static const struct of_device_id pcf85063_of_match[] = {
{ .compatible = "nxp,pcf85063" }, { .compatible = "nxp,pcf85063", .data = &pcf85063tp_config },
{ .compatible = "nxp,pcf85063tp", .data = &pcf85063tp_config },
{ .compatible = "nxp,pcf85063a", .data = &pcf85063a_config },
{ .compatible = "microcrystal,rv8263", .data = &rv8263_config },
{} {}
}; };
MODULE_DEVICE_TABLE(of, pcf85063_of_match); MODULE_DEVICE_TABLE(of, pcf85063_of_match);
...@@ -255,8 +488,7 @@ static struct i2c_driver pcf85063_driver = { ...@@ -255,8 +488,7 @@ static struct i2c_driver pcf85063_driver = {
.name = "rtc-pcf85063", .name = "rtc-pcf85063",
.of_match_table = of_match_ptr(pcf85063_of_match), .of_match_table = of_match_ptr(pcf85063_of_match),
}, },
.probe = pcf85063_probe, .probe_new = pcf85063_probe,
.id_table = pcf85063_id,
}; };
module_i2c_driver(pcf85063_driver); module_i2c_driver(pcf85063_driver);
......
// SPDX-License-Identifier: GPL-2.0
/* /*
* drivers/rtc/rtc-pcf85363.c * drivers/rtc/rtc-pcf85363.c
* *
* Driver for NXP PCF85363 real-time clock. * Driver for NXP PCF85363 real-time clock.
* *
* Copyright (C) 2017 Eric Nelson * Copyright (C) 2017 Eric Nelson
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* Based loosely on rtc-8583 by Russell King, Wolfram Sang and Juergen Beisert
*/ */
#include <linux/module.h> #include <linux/module.h>
#include <linux/i2c.h> #include <linux/i2c.h>
...@@ -112,10 +107,7 @@ ...@@ -112,10 +107,7 @@
#define NVRAM_SIZE 0x40 #define NVRAM_SIZE 0x40
static struct i2c_driver pcf85363_driver;
struct pcf85363 { struct pcf85363 {
struct device *dev;
struct rtc_device *rtc; struct rtc_device *rtc;
struct regmap *regmap; struct regmap *regmap;
}; };
...@@ -386,9 +378,6 @@ static int pcf85363_probe(struct i2c_client *client, ...@@ -386,9 +378,6 @@ static int pcf85363_probe(struct i2c_client *client,
if (data) if (data)
config = data; config = data;
if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
return -ENODEV;
pcf85363 = devm_kzalloc(&client->dev, sizeof(struct pcf85363), pcf85363 = devm_kzalloc(&client->dev, sizeof(struct pcf85363),
GFP_KERNEL); GFP_KERNEL);
if (!pcf85363) if (!pcf85363)
...@@ -400,20 +389,21 @@ static int pcf85363_probe(struct i2c_client *client, ...@@ -400,20 +389,21 @@ static int pcf85363_probe(struct i2c_client *client,
return PTR_ERR(pcf85363->regmap); return PTR_ERR(pcf85363->regmap);
} }
pcf85363->dev = &client->dev;
i2c_set_clientdata(client, pcf85363); i2c_set_clientdata(client, pcf85363);
pcf85363->rtc = devm_rtc_allocate_device(pcf85363->dev); pcf85363->rtc = devm_rtc_allocate_device(&client->dev);
if (IS_ERR(pcf85363->rtc)) if (IS_ERR(pcf85363->rtc))
return PTR_ERR(pcf85363->rtc); return PTR_ERR(pcf85363->rtc);
pcf85363->rtc->ops = &rtc_ops; pcf85363->rtc->ops = &rtc_ops;
pcf85363->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
pcf85363->rtc->range_max = RTC_TIMESTAMP_END_2099;
if (client->irq > 0) { if (client->irq > 0) {
regmap_write(pcf85363->regmap, CTRL_FLAGS, 0); regmap_write(pcf85363->regmap, CTRL_FLAGS, 0);
regmap_update_bits(pcf85363->regmap, CTRL_PIN_IO, regmap_update_bits(pcf85363->regmap, CTRL_PIN_IO,
PIN_IO_INTA_OUT, PIN_IO_INTAPM); PIN_IO_INTA_OUT, PIN_IO_INTAPM);
ret = devm_request_threaded_irq(pcf85363->dev, client->irq, ret = devm_request_threaded_irq(&client->dev, client->irq,
NULL, pcf85363_rtc_handle_irq, NULL, pcf85363_rtc_handle_irq,
IRQF_TRIGGER_LOW | IRQF_ONESHOT, IRQF_TRIGGER_LOW | IRQF_ONESHOT,
"pcf85363", client); "pcf85363", client);
......
// SPDX-License-Identifier: GPL-2.0
/* /*
* PS3 RTC Driver * PS3 RTC Driver
* *
* Copyright 2009 Sony Corporation * Copyright 2009 Sony Corporation
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <linux/kernel.h> #include <linux/kernel.h>
...@@ -40,16 +28,13 @@ static u64 read_rtc(void) ...@@ -40,16 +28,13 @@ static u64 read_rtc(void)
static int ps3_get_time(struct device *dev, struct rtc_time *tm) static int ps3_get_time(struct device *dev, struct rtc_time *tm)
{ {
rtc_time_to_tm(read_rtc() + ps3_os_area_get_rtc_diff(), tm); rtc_time64_to_tm(read_rtc() + ps3_os_area_get_rtc_diff(), tm);
return 0; return 0;
} }
static int ps3_set_time(struct device *dev, struct rtc_time *tm) static int ps3_set_time(struct device *dev, struct rtc_time *tm)
{ {
unsigned long now; ps3_os_area_set_rtc_diff(rtc_tm_to_time64(tm) - read_rtc());
rtc_tm_to_time(tm, &now);
ps3_os_area_set_rtc_diff(now - read_rtc());
return 0; return 0;
} }
...@@ -62,13 +47,16 @@ static int __init ps3_rtc_probe(struct platform_device *dev) ...@@ -62,13 +47,16 @@ static int __init ps3_rtc_probe(struct platform_device *dev)
{ {
struct rtc_device *rtc; struct rtc_device *rtc;
rtc = devm_rtc_device_register(&dev->dev, "rtc-ps3", &ps3_rtc_ops, rtc = devm_rtc_allocate_device(&dev->dev);
THIS_MODULE);
if (IS_ERR(rtc)) if (IS_ERR(rtc))
return PTR_ERR(rtc); return PTR_ERR(rtc);
rtc->ops = &ps3_rtc_ops;
rtc->range_max = U64_MAX;
platform_set_drvdata(dev, rtc); platform_set_drvdata(dev, rtc);
return 0;
return rtc_register_device(rtc);
} }
static struct platform_driver ps3_rtc_driver = { static struct platform_driver ps3_rtc_driver = {
......
...@@ -145,8 +145,7 @@ static void rtsr_set_bits(struct pxa_rtc *pxa_rtc, u32 mask) ...@@ -145,8 +145,7 @@ static void rtsr_set_bits(struct pxa_rtc *pxa_rtc, u32 mask)
static irqreturn_t pxa_rtc_irq(int irq, void *dev_id) static irqreturn_t pxa_rtc_irq(int irq, void *dev_id)
{ {
struct platform_device *pdev = to_platform_device(dev_id); struct pxa_rtc *pxa_rtc = dev_get_drvdata(dev_id);
struct pxa_rtc *pxa_rtc = platform_get_drvdata(pdev);
u32 rtsr; u32 rtsr;
unsigned long events = 0; unsigned long events = 0;
......
...@@ -336,8 +336,7 @@ static const struct rtc_class_ops rk808_rtc_ops = { ...@@ -336,8 +336,7 @@ static const struct rtc_class_ops rk808_rtc_ops = {
/* Turn off the alarm if it should not be a wake source. */ /* Turn off the alarm if it should not be a wake source. */
static int rk808_rtc_suspend(struct device *dev) static int rk808_rtc_suspend(struct device *dev)
{ {
struct platform_device *pdev = to_platform_device(dev); struct rk808_rtc *rk808_rtc = dev_get_drvdata(dev);
struct rk808_rtc *rk808_rtc = dev_get_drvdata(&pdev->dev);
if (device_may_wakeup(dev)) if (device_may_wakeup(dev))
enable_irq_wake(rk808_rtc->irq); enable_irq_wake(rk808_rtc->irq);
...@@ -350,8 +349,7 @@ static int rk808_rtc_suspend(struct device *dev) ...@@ -350,8 +349,7 @@ static int rk808_rtc_suspend(struct device *dev)
*/ */
static int rk808_rtc_resume(struct device *dev) static int rk808_rtc_resume(struct device *dev)
{ {
struct platform_device *pdev = to_platform_device(dev); struct rk808_rtc *rk808_rtc = dev_get_drvdata(dev);
struct rk808_rtc *rk808_rtc = dev_get_drvdata(&pdev->dev);
if (device_may_wakeup(dev)) if (device_may_wakeup(dev))
disable_irq_wake(rk808_rtc->irq); disable_irq_wake(rk808_rtc->irq);
......
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
#include <linux/of_gpio.h> #include <linux/of_gpio.h>
#include <linux/regmap.h> #include <linux/regmap.h>
#include <linux/rtc.h> #include <linux/rtc.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
/* RX-6110 Register definitions */ /* RX-6110 Register definitions */
...@@ -379,9 +381,16 @@ static const struct spi_device_id rx6110_id[] = { ...@@ -379,9 +381,16 @@ static const struct spi_device_id rx6110_id[] = {
}; };
MODULE_DEVICE_TABLE(spi, rx6110_id); MODULE_DEVICE_TABLE(spi, rx6110_id);
static const struct of_device_id rx6110_spi_of_match[] = {
{ .compatible = "epson,rx6110" },
{ },
};
MODULE_DEVICE_TABLE(of, rx6110_spi_of_match);
static struct spi_driver rx6110_driver = { static struct spi_driver rx6110_driver = {
.driver = { .driver = {
.name = RX6110_DRIVER_NAME, .name = RX6110_DRIVER_NAME,
.of_match_table = of_match_ptr(rx6110_spi_of_match),
}, },
.probe = rx6110_probe, .probe = rx6110_probe,
.remove = rx6110_remove, .remove = rx6110_remove,
......
...@@ -311,7 +311,7 @@ static int rx8025_read_alarm(struct device *dev, struct rtc_wkalrm *t) ...@@ -311,7 +311,7 @@ static int rx8025_read_alarm(struct device *dev, struct rtc_wkalrm *t)
t->time.tm_hour = bcd2bin(ald[1] & 0x1f) % 12 t->time.tm_hour = bcd2bin(ald[1] & 0x1f) % 12
+ (ald[1] & 0x20 ? 12 : 0); + (ald[1] & 0x20 ? 12 : 0);
dev_dbg(dev, "%s: date: %ptRr\n", __func__, t); dev_dbg(dev, "%s: date: %ptRr\n", __func__, &t->time);
t->enabled = !!(rx8025->ctrl1 & RX8025_BIT_CTRL1_DALE); t->enabled = !!(rx8025->ctrl1 & RX8025_BIT_CTRL1_DALE);
t->pending = (ctrl2 & RX8025_BIT_CTRL2_DAFG) && t->enabled; t->pending = (ctrl2 & RX8025_BIT_CTRL2_DAFG) && t->enabled;
......
...@@ -276,6 +276,9 @@ static int sh_rtc_read_time(struct device *dev, struct rtc_time *tm) ...@@ -276,6 +276,9 @@ static int sh_rtc_read_time(struct device *dev, struct rtc_time *tm)
struct sh_rtc *rtc = dev_get_drvdata(dev); struct sh_rtc *rtc = dev_get_drvdata(dev);
unsigned int sec128, sec2, yr, yr100, cf_bit; unsigned int sec128, sec2, yr, yr100, cf_bit;
if (!(readb(rtc->regbase + RCR2) & RCR2_RTCEN))
return -EINVAL;
do { do {
unsigned int tmp; unsigned int tmp;
...@@ -466,7 +469,6 @@ static int __init sh_rtc_probe(struct platform_device *pdev) ...@@ -466,7 +469,6 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
{ {
struct sh_rtc *rtc; struct sh_rtc *rtc;
struct resource *res; struct resource *res;
struct rtc_time r;
char clk_name[6]; char clk_name[6];
int clk_id, ret; int clk_id, ret;
...@@ -528,6 +530,10 @@ static int __init sh_rtc_probe(struct platform_device *pdev) ...@@ -528,6 +530,10 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
rtc->clk = NULL; rtc->clk = NULL;
} }
rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev);
if (IS_ERR(rtc->rtc_dev))
return PTR_ERR(rtc->rtc_dev);
clk_enable(rtc->clk); clk_enable(rtc->clk);
rtc->capabilities = RTC_DEF_CAPABILITIES; rtc->capabilities = RTC_DEF_CAPABILITIES;
...@@ -591,21 +597,21 @@ static int __init sh_rtc_probe(struct platform_device *pdev) ...@@ -591,21 +597,21 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
sh_rtc_setaie(&pdev->dev, 0); sh_rtc_setaie(&pdev->dev, 0);
sh_rtc_setcie(&pdev->dev, 0); sh_rtc_setcie(&pdev->dev, 0);
rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, "sh", rtc->rtc_dev->ops = &sh_rtc_ops;
&sh_rtc_ops, THIS_MODULE);
if (IS_ERR(rtc->rtc_dev)) {
ret = PTR_ERR(rtc->rtc_dev);
goto err_unmap;
}
rtc->rtc_dev->max_user_freq = 256; rtc->rtc_dev->max_user_freq = 256;
/* reset rtc to epoch 0 if time is invalid */ if (rtc->capabilities & RTC_CAP_4_DIGIT_YEAR) {
if (rtc_read_time(rtc->rtc_dev, &r) < 0) { rtc->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_1900;
rtc_time_to_tm(0, &r); rtc->rtc_dev->range_max = RTC_TIMESTAMP_END_9999;
rtc_set_time(rtc->rtc_dev, &r); } else {
rtc->rtc_dev->range_min = mktime64(1999, 1, 1, 0, 0, 0);
rtc->rtc_dev->range_max = mktime64(2098, 12, 31, 23, 59, 59);
} }
ret = rtc_register_device(rtc->rtc_dev);
if (ret)
goto err_unmap;
device_init_wakeup(&pdev->dev, 1); device_init_wakeup(&pdev->dev, 1);
return 0; return 0;
......
...@@ -279,7 +279,7 @@ static const struct of_device_id sirfsoc_rtc_of_match[] = { ...@@ -279,7 +279,7 @@ static const struct of_device_id sirfsoc_rtc_of_match[] = {
{}, {},
}; };
const struct regmap_config sysrtc_regmap_config = { static const struct regmap_config sysrtc_regmap_config = {
.reg_bits = 32, .reg_bits = 32,
.val_bits = 32, .val_bits = 32,
.fast_io = true, .fast_io = true,
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <linux/of.h> #include <linux/of.h>
#include <linux/of_device.h> #include <linux/of_device.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/pm_wakeirq.h>
#include <linux/rtc.h> #include <linux/rtc.h>
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/mfd/syscon.h> #include <linux/mfd/syscon.h>
...@@ -271,7 +272,6 @@ static const struct regmap_config snvs_rtc_config = { ...@@ -271,7 +272,6 @@ static const struct regmap_config snvs_rtc_config = {
static int snvs_rtc_probe(struct platform_device *pdev) static int snvs_rtc_probe(struct platform_device *pdev)
{ {
struct snvs_rtc_data *data; struct snvs_rtc_data *data;
struct resource *res;
int ret; int ret;
void __iomem *mmio; void __iomem *mmio;
...@@ -283,9 +283,8 @@ static int snvs_rtc_probe(struct platform_device *pdev) ...@@ -283,9 +283,8 @@ static int snvs_rtc_probe(struct platform_device *pdev)
if (IS_ERR(data->regmap)) { if (IS_ERR(data->regmap)) {
dev_warn(&pdev->dev, "snvs rtc: you use old dts file, please update it\n"); dev_warn(&pdev->dev, "snvs rtc: you use old dts file, please update it\n");
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
mmio = devm_ioremap_resource(&pdev->dev, res); mmio = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(mmio)) if (IS_ERR(mmio))
return PTR_ERR(mmio); return PTR_ERR(mmio);
...@@ -332,6 +331,9 @@ static int snvs_rtc_probe(struct platform_device *pdev) ...@@ -332,6 +331,9 @@ static int snvs_rtc_probe(struct platform_device *pdev)
} }
device_init_wakeup(&pdev->dev, true); device_init_wakeup(&pdev->dev, true);
ret = dev_pm_set_wake_irq(&pdev->dev, data->irq);
if (ret)
dev_err(&pdev->dev, "failed to enable irq wake\n");
ret = devm_request_irq(&pdev->dev, data->irq, snvs_rtc_irq_handler, ret = devm_request_irq(&pdev->dev, data->irq, snvs_rtc_irq_handler,
IRQF_SHARED, "rtc alarm", &pdev->dev); IRQF_SHARED, "rtc alarm", &pdev->dev);
...@@ -358,18 +360,7 @@ static int snvs_rtc_probe(struct platform_device *pdev) ...@@ -358,18 +360,7 @@ static int snvs_rtc_probe(struct platform_device *pdev)
return ret; return ret;
} }
#ifdef CONFIG_PM_SLEEP static int __maybe_unused snvs_rtc_suspend_noirq(struct device *dev)
static int snvs_rtc_suspend(struct device *dev)
{
struct snvs_rtc_data *data = dev_get_drvdata(dev);
if (device_may_wakeup(dev))
return enable_irq_wake(data->irq);
return 0;
}
static int snvs_rtc_suspend_noirq(struct device *dev)
{ {
struct snvs_rtc_data *data = dev_get_drvdata(dev); struct snvs_rtc_data *data = dev_get_drvdata(dev);
...@@ -379,17 +370,7 @@ static int snvs_rtc_suspend_noirq(struct device *dev) ...@@ -379,17 +370,7 @@ static int snvs_rtc_suspend_noirq(struct device *dev)
return 0; return 0;
} }
static int snvs_rtc_resume(struct device *dev) static int __maybe_unused snvs_rtc_resume_noirq(struct device *dev)
{
struct snvs_rtc_data *data = dev_get_drvdata(dev);
if (device_may_wakeup(dev))
return disable_irq_wake(data->irq);
return 0;
}
static int snvs_rtc_resume_noirq(struct device *dev)
{ {
struct snvs_rtc_data *data = dev_get_drvdata(dev); struct snvs_rtc_data *data = dev_get_drvdata(dev);
...@@ -400,20 +381,9 @@ static int snvs_rtc_resume_noirq(struct device *dev) ...@@ -400,20 +381,9 @@ static int snvs_rtc_resume_noirq(struct device *dev)
} }
static const struct dev_pm_ops snvs_rtc_pm_ops = { static const struct dev_pm_ops snvs_rtc_pm_ops = {
.suspend = snvs_rtc_suspend, SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(snvs_rtc_suspend_noirq, snvs_rtc_resume_noirq)
.suspend_noirq = snvs_rtc_suspend_noirq,
.resume = snvs_rtc_resume,
.resume_noirq = snvs_rtc_resume_noirq,
}; };
#define SNVS_RTC_PM_OPS (&snvs_rtc_pm_ops)
#else
#define SNVS_RTC_PM_OPS NULL
#endif
static const struct of_device_id snvs_dt_ids[] = { static const struct of_device_id snvs_dt_ids[] = {
{ .compatible = "fsl,sec-v4.0-mon-rtc-lp", }, { .compatible = "fsl,sec-v4.0-mon-rtc-lp", },
{ /* sentinel */ } { /* sentinel */ }
...@@ -423,7 +393,7 @@ MODULE_DEVICE_TABLE(of, snvs_dt_ids); ...@@ -423,7 +393,7 @@ MODULE_DEVICE_TABLE(of, snvs_dt_ids);
static struct platform_driver snvs_rtc_driver = { static struct platform_driver snvs_rtc_driver = {
.driver = { .driver = {
.name = "snvs_rtc", .name = "snvs_rtc",
.pm = SNVS_RTC_PM_OPS, .pm = &snvs_rtc_pm_ops,
.of_match_table = snvs_dt_ids, .of_match_table = snvs_dt_ids,
}, },
.probe = snvs_rtc_probe, .probe = snvs_rtc_probe,
......
...@@ -788,11 +788,14 @@ static int stm32_rtc_probe(struct platform_device *pdev) ...@@ -788,11 +788,14 @@ static int stm32_rtc_probe(struct platform_device *pdev)
ret = device_init_wakeup(&pdev->dev, true); ret = device_init_wakeup(&pdev->dev, true);
if (rtc->data->has_wakeirq) { if (rtc->data->has_wakeirq) {
rtc->wakeirq_alarm = platform_get_irq(pdev, 1); rtc->wakeirq_alarm = platform_get_irq(pdev, 1);
if (rtc->wakeirq_alarm <= 0) if (rtc->wakeirq_alarm > 0) {
ret = rtc->wakeirq_alarm;
else
ret = dev_pm_set_dedicated_wake_irq(&pdev->dev, ret = dev_pm_set_dedicated_wake_irq(&pdev->dev,
rtc->wakeirq_alarm); rtc->wakeirq_alarm);
} else {
ret = rtc->wakeirq_alarm;
if (rtc->wakeirq_alarm == -EPROBE_DEFER)
goto err;
}
} }
if (ret) if (ret)
dev_warn(&pdev->dev, "alarm can't wake up the system: %d", ret); dev_warn(&pdev->dev, "alarm can't wake up the system: %d", ret);
......
// SPDX-License-Identifier: GPL-2.0+
/* /*
* Freescale STMP37XX/STMP378X Real Time Clock driver * Freescale STMP37XX/STMP378X Real Time Clock driver
* *
...@@ -8,15 +9,6 @@ ...@@ -8,15 +9,6 @@
* Copyright 2008 Embedded Alley Solutions, Inc All Rights Reserved. * Copyright 2008 Embedded Alley Solutions, Inc All Rights Reserved.
* Copyright 2011 Wolfram Sang, Pengutronix e.K. * Copyright 2011 Wolfram Sang, Pengutronix e.K.
*/ */
/*
* The code contained herein is licensed under the GNU General Public
* License. You may obtain a copy of the GNU General Public License
* Version 2 or later at the following locations:
*
* http://www.opensource.org/licenses/gpl-license.html
* http://www.gnu.org/copyleft/gpl.html
*/
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/io.h> #include <linux/io.h>
...@@ -160,15 +152,15 @@ static int stmp3xxx_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm) ...@@ -160,15 +152,15 @@ static int stmp3xxx_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm)
if (ret) if (ret)
return ret; return ret;
rtc_time_to_tm(readl(rtc_data->io + STMP3XXX_RTC_SECONDS), rtc_tm); rtc_time64_to_tm(readl(rtc_data->io + STMP3XXX_RTC_SECONDS), rtc_tm);
return 0; return 0;
} }
static int stmp3xxx_rtc_set_mmss(struct device *dev, unsigned long t) static int stmp3xxx_rtc_settime(struct device *dev, struct rtc_time *rtc_tm)
{ {
struct stmp3xxx_rtc_data *rtc_data = dev_get_drvdata(dev); struct stmp3xxx_rtc_data *rtc_data = dev_get_drvdata(dev);
writel(t, rtc_data->io + STMP3XXX_RTC_SECONDS); writel(rtc_tm_to_time64(rtc_tm), rtc_data->io + STMP3XXX_RTC_SECONDS);
return stmp3xxx_wait_time(rtc_data); return stmp3xxx_wait_time(rtc_data);
} }
...@@ -214,17 +206,15 @@ static int stmp3xxx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm) ...@@ -214,17 +206,15 @@ static int stmp3xxx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
{ {
struct stmp3xxx_rtc_data *rtc_data = dev_get_drvdata(dev); struct stmp3xxx_rtc_data *rtc_data = dev_get_drvdata(dev);
rtc_time_to_tm(readl(rtc_data->io + STMP3XXX_RTC_ALARM), &alm->time); rtc_time64_to_tm(readl(rtc_data->io + STMP3XXX_RTC_ALARM), &alm->time);
return 0; return 0;
} }
static int stmp3xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm) static int stmp3xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
{ {
unsigned long t;
struct stmp3xxx_rtc_data *rtc_data = dev_get_drvdata(dev); struct stmp3xxx_rtc_data *rtc_data = dev_get_drvdata(dev);
rtc_tm_to_time(&alm->time, &t); writel(rtc_tm_to_time64(&alm->time), rtc_data->io + STMP3XXX_RTC_ALARM);
writel(t, rtc_data->io + STMP3XXX_RTC_ALARM);
stmp3xxx_alarm_irq_enable(dev, alm->enabled); stmp3xxx_alarm_irq_enable(dev, alm->enabled);
...@@ -235,7 +225,7 @@ static const struct rtc_class_ops stmp3xxx_rtc_ops = { ...@@ -235,7 +225,7 @@ static const struct rtc_class_ops stmp3xxx_rtc_ops = {
.alarm_irq_enable = .alarm_irq_enable =
stmp3xxx_alarm_irq_enable, stmp3xxx_alarm_irq_enable,
.read_time = stmp3xxx_rtc_gettime, .read_time = stmp3xxx_rtc_gettime,
.set_mmss = stmp3xxx_rtc_set_mmss, .set_time = stmp3xxx_rtc_settime,
.read_alarm = stmp3xxx_rtc_read_alarm, .read_alarm = stmp3xxx_rtc_read_alarm,
.set_alarm = stmp3xxx_rtc_set_alarm, .set_alarm = stmp3xxx_rtc_set_alarm,
}; };
...@@ -361,8 +351,7 @@ static int stmp3xxx_rtc_probe(struct platform_device *pdev) ...@@ -361,8 +351,7 @@ static int stmp3xxx_rtc_probe(struct platform_device *pdev)
STMP3XXX_RTC_CTRL_ALARM_IRQ_EN, STMP3XXX_RTC_CTRL_ALARM_IRQ_EN,
rtc_data->io + STMP3XXX_RTC_CTRL + STMP_OFFSET_REG_CLR); rtc_data->io + STMP3XXX_RTC_CTRL + STMP_OFFSET_REG_CLR);
rtc_data->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, rtc_data->rtc = devm_rtc_allocate_device(&pdev->dev);
&stmp3xxx_rtc_ops, THIS_MODULE);
if (IS_ERR(rtc_data->rtc)) if (IS_ERR(rtc_data->rtc))
return PTR_ERR(rtc_data->rtc); return PTR_ERR(rtc_data->rtc);
...@@ -374,6 +363,13 @@ static int stmp3xxx_rtc_probe(struct platform_device *pdev) ...@@ -374,6 +363,13 @@ static int stmp3xxx_rtc_probe(struct platform_device *pdev)
return err; return err;
} }
rtc_data->rtc->ops = &stmp3xxx_rtc_ops;
rtc_data->rtc->range_max = U32_MAX;
err = rtc_register_device(rtc_data->rtc);
if (err)
return err;
stmp3xxx_wdt_register(pdev); stmp3xxx_wdt_register(pdev);
return 0; return 0;
} }
......
// SPDX-License-Identifier: GPL-2.0
/* rtc-sun4v.c: Hypervisor based RTC for SUN4V systems. /* rtc-sun4v.c: Hypervisor based RTC for SUN4V systems.
* *
* Author: David S. Miller * Author: David S. Miller
* License: GPL
* *
* Copyright (C) 2008 David S. Miller <davem@davemloft.net> * Copyright (C) 2008 David S. Miller <davem@davemloft.net>
*/ */
...@@ -39,7 +39,7 @@ static unsigned long hypervisor_get_time(void) ...@@ -39,7 +39,7 @@ static unsigned long hypervisor_get_time(void)
static int sun4v_read_time(struct device *dev, struct rtc_time *tm) static int sun4v_read_time(struct device *dev, struct rtc_time *tm)
{ {
rtc_time_to_tm(hypervisor_get_time(), tm); rtc_time64_to_tm(hypervisor_get_time(), tm);
return 0; return 0;
} }
...@@ -66,14 +66,7 @@ static int hypervisor_set_time(unsigned long secs) ...@@ -66,14 +66,7 @@ static int hypervisor_set_time(unsigned long secs)
static int sun4v_set_time(struct device *dev, struct rtc_time *tm) static int sun4v_set_time(struct device *dev, struct rtc_time *tm)
{ {
unsigned long secs; return hypervisor_set_time(rtc_tm_to_time64(tm));
int err;
err = rtc_tm_to_time(tm, &secs);
if (err)
return err;
return hypervisor_set_time(secs);
} }
static const struct rtc_class_ops sun4v_rtc_ops = { static const struct rtc_class_ops sun4v_rtc_ops = {
...@@ -85,13 +78,15 @@ static int __init sun4v_rtc_probe(struct platform_device *pdev) ...@@ -85,13 +78,15 @@ static int __init sun4v_rtc_probe(struct platform_device *pdev)
{ {
struct rtc_device *rtc; struct rtc_device *rtc;
rtc = devm_rtc_device_register(&pdev->dev, "sun4v", rtc = devm_rtc_allocate_device(&pdev->dev);
&sun4v_rtc_ops, THIS_MODULE);
if (IS_ERR(rtc)) if (IS_ERR(rtc))
return PTR_ERR(rtc); return PTR_ERR(rtc);
rtc->ops = &sun4v_rtc_ops;
rtc->range_max = U64_MAX;
platform_set_drvdata(pdev, rtc); platform_set_drvdata(pdev, rtc);
return 0;
return rtc_register_device(rtc);
} }
static struct platform_driver sun4v_rtc_driver = { static struct platform_driver sun4v_rtc_driver = {
......
// SPDX-License-Identifier: GPL-2.0+
/* /*
* An RTC driver for the NVIDIA Tegra 200 series internal RTC. * An RTC driver for the NVIDIA Tegra 200 series internal RTC.
* *
* Copyright (c) 2010, NVIDIA Corporation. * Copyright (c) 2010, NVIDIA Corporation.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#include <linux/clk.h> #include <linux/clk.h>
...@@ -123,7 +110,7 @@ static int tegra_rtc_read_time(struct device *dev, struct rtc_time *tm) ...@@ -123,7 +110,7 @@ static int tegra_rtc_read_time(struct device *dev, struct rtc_time *tm)
spin_unlock_irqrestore(&info->tegra_rtc_lock, sl_irq_flags); spin_unlock_irqrestore(&info->tegra_rtc_lock, sl_irq_flags);
rtc_time_to_tm(sec, tm); rtc_time64_to_tm(sec, tm);
dev_vdbg(dev, "time read as %lu. %ptR\n", sec, tm); dev_vdbg(dev, "time read as %lu. %ptR\n", sec, tm);
...@@ -137,7 +124,7 @@ static int tegra_rtc_set_time(struct device *dev, struct rtc_time *tm) ...@@ -137,7 +124,7 @@ static int tegra_rtc_set_time(struct device *dev, struct rtc_time *tm)
int ret; int ret;
/* convert tm to seconds. */ /* convert tm to seconds. */
rtc_tm_to_time(tm, &sec); sec = rtc_tm_to_time64(tm);
dev_vdbg(dev, "time set to %lu. %ptR\n", sec, tm); dev_vdbg(dev, "time set to %lu. %ptR\n", sec, tm);
...@@ -166,7 +153,7 @@ static int tegra_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) ...@@ -166,7 +153,7 @@ static int tegra_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
} else { } else {
/* alarm is enabled. */ /* alarm is enabled. */
alarm->enabled = 1; alarm->enabled = 1;
rtc_time_to_tm(sec, &alarm->time); rtc_time64_to_tm(sec, &alarm->time);
} }
tmp = readl(info->rtc_base + TEGRA_RTC_REG_INTR_STATUS); tmp = readl(info->rtc_base + TEGRA_RTC_REG_INTR_STATUS);
...@@ -204,7 +191,7 @@ static int tegra_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) ...@@ -204,7 +191,7 @@ static int tegra_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
unsigned long sec; unsigned long sec;
if (alarm->enabled) if (alarm->enabled)
rtc_tm_to_time(&alarm->time, &sec); sec = rtc_tm_to_time64(&alarm->time);
else else
sec = 0; sec = 0;
...@@ -306,6 +293,13 @@ static int __init tegra_rtc_probe(struct platform_device *pdev) ...@@ -306,6 +293,13 @@ static int __init tegra_rtc_probe(struct platform_device *pdev)
info->tegra_rtc_irq = ret; info->tegra_rtc_irq = ret;
info->rtc_dev = devm_rtc_allocate_device(&pdev->dev);
if (IS_ERR(info->rtc_dev))
return PTR_ERR(info->rtc_dev);
info->rtc_dev->ops = &tegra_rtc_ops;
info->rtc_dev->range_max = U32_MAX;
info->clk = devm_clk_get(&pdev->dev, NULL); info->clk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(info->clk)) if (IS_ERR(info->clk))
return PTR_ERR(info->clk); return PTR_ERR(info->clk);
...@@ -327,16 +321,6 @@ static int __init tegra_rtc_probe(struct platform_device *pdev) ...@@ -327,16 +321,6 @@ static int __init tegra_rtc_probe(struct platform_device *pdev)
device_init_wakeup(&pdev->dev, 1); device_init_wakeup(&pdev->dev, 1);
info->rtc_dev = devm_rtc_device_register(&pdev->dev,
dev_name(&pdev->dev), &tegra_rtc_ops,
THIS_MODULE);
if (IS_ERR(info->rtc_dev)) {
ret = PTR_ERR(info->rtc_dev);
dev_err(&pdev->dev, "Unable to register device (err=%d).\n",
ret);
goto disable_clk;
}
ret = devm_request_irq(&pdev->dev, info->tegra_rtc_irq, ret = devm_request_irq(&pdev->dev, info->tegra_rtc_irq,
tegra_rtc_irq_handler, IRQF_TRIGGER_HIGH, tegra_rtc_irq_handler, IRQF_TRIGGER_HIGH,
dev_name(&pdev->dev), &pdev->dev); dev_name(&pdev->dev), &pdev->dev);
...@@ -347,6 +331,13 @@ static int __init tegra_rtc_probe(struct platform_device *pdev) ...@@ -347,6 +331,13 @@ static int __init tegra_rtc_probe(struct platform_device *pdev)
goto disable_clk; goto disable_clk;
} }
ret = rtc_register_device(info->rtc_dev);
if (ret) {
dev_err(&pdev->dev, "Unable to register device (err=%d).\n",
ret);
goto disable_clk;
}
dev_notice(&pdev->dev, "Tegra internal Real Time Clock\n"); dev_notice(&pdev->dev, "Tegra internal Real Time Clock\n");
return 0; return 0;
......
...@@ -70,11 +70,11 @@ static int test_rtc_read_time(struct device *dev, struct rtc_time *tm) ...@@ -70,11 +70,11 @@ static int test_rtc_read_time(struct device *dev, struct rtc_time *tm)
return 0; return 0;
} }
static int test_rtc_set_mmss64(struct device *dev, time64_t secs) static int test_rtc_set_time(struct device *dev, struct rtc_time *tm)
{ {
struct rtc_test_data *rtd = dev_get_drvdata(dev); struct rtc_test_data *rtd = dev_get_drvdata(dev);
rtd->offset = secs - ktime_get_real_seconds(); rtd->offset = rtc_tm_to_time64(tm) - ktime_get_real_seconds();
return 0; return 0;
} }
...@@ -94,15 +94,15 @@ static int test_rtc_alarm_irq_enable(struct device *dev, unsigned int enable) ...@@ -94,15 +94,15 @@ static int test_rtc_alarm_irq_enable(struct device *dev, unsigned int enable)
static const struct rtc_class_ops test_rtc_ops_noalm = { static const struct rtc_class_ops test_rtc_ops_noalm = {
.read_time = test_rtc_read_time, .read_time = test_rtc_read_time,
.set_mmss64 = test_rtc_set_mmss64, .set_time = test_rtc_set_time,
.alarm_irq_enable = test_rtc_alarm_irq_enable, .alarm_irq_enable = test_rtc_alarm_irq_enable,
}; };
static const struct rtc_class_ops test_rtc_ops = { static const struct rtc_class_ops test_rtc_ops = {
.read_time = test_rtc_read_time, .read_time = test_rtc_read_time,
.set_time = test_rtc_set_time,
.read_alarm = test_rtc_read_alarm, .read_alarm = test_rtc_read_alarm,
.set_alarm = test_rtc_set_alarm, .set_alarm = test_rtc_set_alarm,
.set_mmss64 = test_rtc_set_mmss64,
.alarm_irq_enable = test_rtc_alarm_irq_enable, .alarm_irq_enable = test_rtc_alarm_irq_enable,
}; };
...@@ -152,7 +152,8 @@ static int __init test_init(void) ...@@ -152,7 +152,8 @@ static int __init test_init(void)
{ {
int i, err; int i, err;
if ((err = platform_driver_register(&test_driver))) err = platform_driver_register(&test_driver);
if (err)
return err; return err;
err = -ENOMEM; err = -ENOMEM;
......
...@@ -42,11 +42,6 @@ struct tx4939rtc_plat_data { ...@@ -42,11 +42,6 @@ struct tx4939rtc_plat_data {
spinlock_t lock; spinlock_t lock;
}; };
static struct tx4939rtc_plat_data *get_tx4939rtc_plat_data(struct device *dev)
{
return platform_get_drvdata(to_platform_device(dev));
}
static int tx4939_rtc_cmd(struct tx4939_rtc_reg __iomem *rtcreg, int cmd) static int tx4939_rtc_cmd(struct tx4939_rtc_reg __iomem *rtcreg, int cmd)
{ {
int i = 0; int i = 0;
...@@ -64,7 +59,7 @@ static int tx4939_rtc_cmd(struct tx4939_rtc_reg __iomem *rtcreg, int cmd) ...@@ -64,7 +59,7 @@ static int tx4939_rtc_cmd(struct tx4939_rtc_reg __iomem *rtcreg, int cmd)
static int tx4939_rtc_set_time(struct device *dev, struct rtc_time *tm) static int tx4939_rtc_set_time(struct device *dev, struct rtc_time *tm)
{ {
struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev); struct tx4939rtc_plat_data *pdata = dev_get_drvdata(dev);
struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg; struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg;
unsigned long secs = rtc_tm_to_time64(tm); unsigned long secs = rtc_tm_to_time64(tm);
int i, ret; int i, ret;
...@@ -89,7 +84,7 @@ static int tx4939_rtc_set_time(struct device *dev, struct rtc_time *tm) ...@@ -89,7 +84,7 @@ static int tx4939_rtc_set_time(struct device *dev, struct rtc_time *tm)
static int tx4939_rtc_read_time(struct device *dev, struct rtc_time *tm) static int tx4939_rtc_read_time(struct device *dev, struct rtc_time *tm)
{ {
struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev); struct tx4939rtc_plat_data *pdata = dev_get_drvdata(dev);
struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg; struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg;
int i, ret; int i, ret;
unsigned long sec; unsigned long sec;
...@@ -115,7 +110,7 @@ static int tx4939_rtc_read_time(struct device *dev, struct rtc_time *tm) ...@@ -115,7 +110,7 @@ static int tx4939_rtc_read_time(struct device *dev, struct rtc_time *tm)
static int tx4939_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) static int tx4939_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{ {
struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev); struct tx4939rtc_plat_data *pdata = dev_get_drvdata(dev);
struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg; struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg;
int i, ret; int i, ret;
unsigned long sec; unsigned long sec;
...@@ -140,7 +135,7 @@ static int tx4939_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) ...@@ -140,7 +135,7 @@ static int tx4939_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
static int tx4939_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) static int tx4939_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{ {
struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev); struct tx4939rtc_plat_data *pdata = dev_get_drvdata(dev);
struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg; struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg;
int i, ret; int i, ret;
unsigned long sec; unsigned long sec;
...@@ -170,7 +165,7 @@ static int tx4939_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) ...@@ -170,7 +165,7 @@ static int tx4939_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
static int tx4939_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) static int tx4939_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
{ {
struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev); struct tx4939rtc_plat_data *pdata = dev_get_drvdata(dev);
spin_lock_irq(&pdata->lock); spin_lock_irq(&pdata->lock);
tx4939_rtc_cmd(pdata->rtcreg, tx4939_rtc_cmd(pdata->rtcreg,
...@@ -182,7 +177,7 @@ static int tx4939_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) ...@@ -182,7 +177,7 @@ static int tx4939_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
static irqreturn_t tx4939_rtc_interrupt(int irq, void *dev_id) static irqreturn_t tx4939_rtc_interrupt(int irq, void *dev_id)
{ {
struct tx4939rtc_plat_data *pdata = get_tx4939rtc_plat_data(dev_id); struct tx4939rtc_plat_data *pdata = dev_get_drvdata(dev_id);
struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg; struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg;
unsigned long events = RTC_IRQF; unsigned long events = RTC_IRQF;
......
// SPDX-License-Identifier: GPL-2.0+
/* /*
* Real Time Clock driver for Wolfson Microelectronics WM831x * Real Time Clock driver for Wolfson Microelectronics WM831x
* *
...@@ -5,11 +6,6 @@ ...@@ -5,11 +6,6 @@
* *
* Author: Mark Brown <broonie@opensource.wolfsonmicro.com> * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
* *
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
*/ */
#include <linux/module.h> #include <linux/module.h>
...@@ -155,7 +151,7 @@ static int wm831x_rtc_readtime(struct device *dev, struct rtc_time *tm) ...@@ -155,7 +151,7 @@ static int wm831x_rtc_readtime(struct device *dev, struct rtc_time *tm)
if (memcmp(time1, time2, sizeof(time1)) == 0) { if (memcmp(time1, time2, sizeof(time1)) == 0) {
u32 time = (time1[0] << 16) | time1[1]; u32 time = (time1[0] << 16) | time1[1];
rtc_time_to_tm(time, tm); rtc_time64_to_tm(time, tm);
return 0; return 0;
} }
...@@ -169,15 +165,17 @@ static int wm831x_rtc_readtime(struct device *dev, struct rtc_time *tm) ...@@ -169,15 +165,17 @@ static int wm831x_rtc_readtime(struct device *dev, struct rtc_time *tm)
/* /*
* Set current time and date in RTC * Set current time and date in RTC
*/ */
static int wm831x_rtc_set_mmss(struct device *dev, unsigned long time) static int wm831x_rtc_settime(struct device *dev, struct rtc_time *tm)
{ {
struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(dev); struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(dev);
struct wm831x *wm831x = wm831x_rtc->wm831x; struct wm831x *wm831x = wm831x_rtc->wm831x;
struct rtc_time new_tm; struct rtc_time new_tm;
unsigned long new_time; unsigned long time, new_time;
int ret; int ret;
int count = 0; int count = 0;
time = rtc_tm_to_time64(tm);
ret = wm831x_reg_write(wm831x, WM831X_RTC_TIME_1, ret = wm831x_reg_write(wm831x, WM831X_RTC_TIME_1,
(time >> 16) & 0xffff); (time >> 16) & 0xffff);
if (ret < 0) { if (ret < 0) {
...@@ -215,11 +213,7 @@ static int wm831x_rtc_set_mmss(struct device *dev, unsigned long time) ...@@ -215,11 +213,7 @@ static int wm831x_rtc_set_mmss(struct device *dev, unsigned long time)
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = rtc_tm_to_time(&new_tm, &new_time); new_time = rtc_tm_to_time64(&new_tm);
if (ret < 0) {
dev_err(dev, "Failed to convert time: %d\n", ret);
return ret;
}
/* Allow a second of change in case of tick */ /* Allow a second of change in case of tick */
if (new_time - time > 1) { if (new_time - time > 1) {
...@@ -249,7 +243,7 @@ static int wm831x_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm) ...@@ -249,7 +243,7 @@ static int wm831x_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
time = (data[0] << 16) | data[1]; time = (data[0] << 16) | data[1];
rtc_time_to_tm(time, &alrm->time); rtc_time64_to_tm(time, &alrm->time);
ret = wm831x_reg_read(wm831x_rtc->wm831x, WM831X_RTC_CONTROL); ret = wm831x_reg_read(wm831x_rtc->wm831x, WM831X_RTC_CONTROL);
if (ret < 0) { if (ret < 0) {
...@@ -288,11 +282,7 @@ static int wm831x_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm) ...@@ -288,11 +282,7 @@ static int wm831x_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
int ret; int ret;
unsigned long time; unsigned long time;
ret = rtc_tm_to_time(&alrm->time, &time); time = rtc_tm_to_time64(&alrm->time);
if (ret < 0) {
dev_err(dev, "Failed to convert time: %d\n", ret);
return ret;
}
ret = wm831x_rtc_stop_alarm(wm831x_rtc); ret = wm831x_rtc_stop_alarm(wm831x_rtc);
if (ret < 0) { if (ret < 0) {
...@@ -346,7 +336,7 @@ static irqreturn_t wm831x_alm_irq(int irq, void *data) ...@@ -346,7 +336,7 @@ static irqreturn_t wm831x_alm_irq(int irq, void *data)
static const struct rtc_class_ops wm831x_rtc_ops = { static const struct rtc_class_ops wm831x_rtc_ops = {
.read_time = wm831x_rtc_readtime, .read_time = wm831x_rtc_readtime,
.set_mmss = wm831x_rtc_set_mmss, .set_time = wm831x_rtc_settime,
.read_alarm = wm831x_rtc_readalarm, .read_alarm = wm831x_rtc_readalarm,
.set_alarm = wm831x_rtc_setalarm, .set_alarm = wm831x_rtc_setalarm,
.alarm_irq_enable = wm831x_rtc_alarm_irq_enable, .alarm_irq_enable = wm831x_rtc_alarm_irq_enable,
...@@ -356,11 +346,10 @@ static const struct rtc_class_ops wm831x_rtc_ops = { ...@@ -356,11 +346,10 @@ static const struct rtc_class_ops wm831x_rtc_ops = {
/* Turn off the alarm if it should not be a wake source. */ /* Turn off the alarm if it should not be a wake source. */
static int wm831x_rtc_suspend(struct device *dev) static int wm831x_rtc_suspend(struct device *dev)
{ {
struct platform_device *pdev = to_platform_device(dev); struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(dev);
struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(&pdev->dev);
int ret, enable; int ret, enable;
if (wm831x_rtc->alarm_enabled && device_may_wakeup(&pdev->dev)) if (wm831x_rtc->alarm_enabled && device_may_wakeup(dev))
enable = WM831X_RTC_ALM_ENA; enable = WM831X_RTC_ALM_ENA;
else else
enable = 0; enable = 0;
...@@ -368,7 +357,7 @@ static int wm831x_rtc_suspend(struct device *dev) ...@@ -368,7 +357,7 @@ static int wm831x_rtc_suspend(struct device *dev)
ret = wm831x_set_bits(wm831x_rtc->wm831x, WM831X_RTC_CONTROL, ret = wm831x_set_bits(wm831x_rtc->wm831x, WM831X_RTC_CONTROL,
WM831X_RTC_ALM_ENA, enable); WM831X_RTC_ALM_ENA, enable);
if (ret != 0) if (ret != 0)
dev_err(&pdev->dev, "Failed to update RTC alarm: %d\n", ret); dev_err(dev, "Failed to update RTC alarm: %d\n", ret);
return 0; return 0;
} }
...@@ -378,15 +367,13 @@ static int wm831x_rtc_suspend(struct device *dev) ...@@ -378,15 +367,13 @@ static int wm831x_rtc_suspend(struct device *dev)
*/ */
static int wm831x_rtc_resume(struct device *dev) static int wm831x_rtc_resume(struct device *dev)
{ {
struct platform_device *pdev = to_platform_device(dev); struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(dev);
struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(&pdev->dev);
int ret; int ret;
if (wm831x_rtc->alarm_enabled) { if (wm831x_rtc->alarm_enabled) {
ret = wm831x_rtc_start_alarm(wm831x_rtc); ret = wm831x_rtc_start_alarm(wm831x_rtc);
if (ret != 0) if (ret != 0)
dev_err(&pdev->dev, dev_err(dev, "Failed to restart RTC alarm: %d\n", ret);
"Failed to restart RTC alarm: %d\n", ret);
} }
return 0; return 0;
...@@ -395,14 +382,13 @@ static int wm831x_rtc_resume(struct device *dev) ...@@ -395,14 +382,13 @@ static int wm831x_rtc_resume(struct device *dev)
/* Unconditionally disable the alarm */ /* Unconditionally disable the alarm */
static int wm831x_rtc_freeze(struct device *dev) static int wm831x_rtc_freeze(struct device *dev)
{ {
struct platform_device *pdev = to_platform_device(dev); struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(dev);
struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(&pdev->dev);
int ret; int ret;
ret = wm831x_set_bits(wm831x_rtc->wm831x, WM831X_RTC_CONTROL, ret = wm831x_set_bits(wm831x_rtc->wm831x, WM831X_RTC_CONTROL,
WM831X_RTC_ALM_ENA, 0); WM831X_RTC_ALM_ENA, 0);
if (ret != 0) if (ret != 0)
dev_err(&pdev->dev, "Failed to stop RTC alarm: %d\n", ret); dev_err(dev, "Failed to stop RTC alarm: %d\n", ret);
return 0; return 0;
} }
...@@ -429,19 +415,23 @@ static int wm831x_rtc_probe(struct platform_device *pdev) ...@@ -429,19 +415,23 @@ static int wm831x_rtc_probe(struct platform_device *pdev)
ret = wm831x_reg_read(wm831x, WM831X_RTC_CONTROL); ret = wm831x_reg_read(wm831x, WM831X_RTC_CONTROL);
if (ret < 0) { if (ret < 0) {
dev_err(&pdev->dev, "Failed to read RTC control: %d\n", ret); dev_err(&pdev->dev, "Failed to read RTC control: %d\n", ret);
goto err; return ret;
} }
if (ret & WM831X_RTC_ALM_ENA) if (ret & WM831X_RTC_ALM_ENA)
wm831x_rtc->alarm_enabled = 1; wm831x_rtc->alarm_enabled = 1;
device_init_wakeup(&pdev->dev, 1); device_init_wakeup(&pdev->dev, 1);
wm831x_rtc->rtc = devm_rtc_device_register(&pdev->dev, "wm831x", wm831x_rtc->rtc = devm_rtc_allocate_device(&pdev->dev);
&wm831x_rtc_ops, THIS_MODULE); if (IS_ERR(wm831x_rtc->rtc))
if (IS_ERR(wm831x_rtc->rtc)) { return PTR_ERR(wm831x_rtc->rtc);
ret = PTR_ERR(wm831x_rtc->rtc);
goto err; wm831x_rtc->rtc->ops = &wm831x_rtc_ops;
} wm831x_rtc->rtc->range_max = U32_MAX;
ret = rtc_register_device(wm831x_rtc->rtc);
if (ret)
return ret;
ret = devm_request_threaded_irq(&pdev->dev, alm_irq, NULL, ret = devm_request_threaded_irq(&pdev->dev, alm_irq, NULL,
wm831x_alm_irq, wm831x_alm_irq,
...@@ -455,9 +445,6 @@ static int wm831x_rtc_probe(struct platform_device *pdev) ...@@ -455,9 +445,6 @@ static int wm831x_rtc_probe(struct platform_device *pdev)
wm831x_rtc_add_randomness(wm831x); wm831x_rtc_add_randomness(wm831x);
return 0; return 0;
err:
return ret;
} }
static const struct dev_pm_ops wm831x_rtc_pm_ops = { static const struct dev_pm_ops wm831x_rtc_pm_ops = {
......
...@@ -340,8 +340,7 @@ static const struct rtc_class_ops wm8350_rtc_ops = { ...@@ -340,8 +340,7 @@ static const struct rtc_class_ops wm8350_rtc_ops = {
#ifdef CONFIG_PM_SLEEP #ifdef CONFIG_PM_SLEEP
static int wm8350_rtc_suspend(struct device *dev) static int wm8350_rtc_suspend(struct device *dev)
{ {
struct platform_device *pdev = to_platform_device(dev); struct wm8350 *wm8350 = dev_get_drvdata(dev);
struct wm8350 *wm8350 = dev_get_drvdata(&pdev->dev);
int ret = 0; int ret = 0;
u16 reg; u16 reg;
...@@ -351,8 +350,7 @@ static int wm8350_rtc_suspend(struct device *dev) ...@@ -351,8 +350,7 @@ static int wm8350_rtc_suspend(struct device *dev)
reg & WM8350_RTC_ALMSTS) { reg & WM8350_RTC_ALMSTS) {
ret = wm8350_rtc_stop_alarm(wm8350); ret = wm8350_rtc_stop_alarm(wm8350);
if (ret != 0) if (ret != 0)
dev_err(&pdev->dev, "Failed to stop RTC alarm: %d\n", dev_err(dev, "Failed to stop RTC alarm: %d\n", ret);
ret);
} }
return ret; return ret;
...@@ -360,15 +358,13 @@ static int wm8350_rtc_suspend(struct device *dev) ...@@ -360,15 +358,13 @@ static int wm8350_rtc_suspend(struct device *dev)
static int wm8350_rtc_resume(struct device *dev) static int wm8350_rtc_resume(struct device *dev)
{ {
struct platform_device *pdev = to_platform_device(dev); struct wm8350 *wm8350 = dev_get_drvdata(dev);
struct wm8350 *wm8350 = dev_get_drvdata(&pdev->dev);
int ret; int ret;
if (wm8350->rtc.alarm_enabled) { if (wm8350->rtc.alarm_enabled) {
ret = wm8350_rtc_start_alarm(wm8350); ret = wm8350_rtc_start_alarm(wm8350);
if (ret != 0) if (ret != 0)
dev_err(&pdev->dev, dev_err(dev, "Failed to restart RTC alarm: %d\n", ret);
"Failed to restart RTC alarm: %d\n", ret);
} }
return 0; return 0;
......
...@@ -673,9 +673,16 @@ static const struct i2c_device_id x1205_id[] = { ...@@ -673,9 +673,16 @@ static const struct i2c_device_id x1205_id[] = {
}; };
MODULE_DEVICE_TABLE(i2c, x1205_id); MODULE_DEVICE_TABLE(i2c, x1205_id);
static const struct of_device_id x1205_dt_ids[] = {
{ .compatible = "xircom,x1205", },
{},
};
MODULE_DEVICE_TABLE(of, x1205_dt_ids);
static struct i2c_driver x1205_driver = { static struct i2c_driver x1205_driver = {
.driver = { .driver = {
.name = "rtc-x1205", .name = "rtc-x1205",
.of_match_table = x1205_dt_ids,
}, },
.probe = x1205_probe, .probe = x1205_probe,
.remove = x1205_remove, .remove = x1205_remove,
......
// SPDX-License-Identifier: GPL-2.0+
/* /*
* APM X-Gene SoC Real Time Clock Driver * APM X-Gene SoC Real Time Clock Driver
* *
* Copyright (c) 2014, Applied Micro Circuits Corporation * Copyright (c) 2014, Applied Micro Circuits Corporation
* Author: Rameshwar Prasad Sahu <rsahu@apm.com> * Author: Rameshwar Prasad Sahu <rsahu@apm.com>
* Loc Ho <lho@apm.com> * Loc Ho <lho@apm.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/ */
#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/io.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/io.h>
#include <linux/slab.h>
#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/rtc.h> #include <linux/rtc.h>
#include <linux/slab.h>
/* RTC CSR Registers */ /* RTC CSR Registers */
#define RTC_CCVR 0x00 #define RTC_CCVR 0x00
...@@ -48,7 +35,6 @@ ...@@ -48,7 +35,6 @@
struct xgene_rtc_dev { struct xgene_rtc_dev {
struct rtc_device *rtc; struct rtc_device *rtc;
struct device *dev; struct device *dev;
unsigned long alarm_time;
void __iomem *csr_base; void __iomem *csr_base;
struct clk *clk; struct clk *clk;
unsigned int irq_wake; unsigned int irq_wake;
...@@ -59,11 +45,11 @@ static int xgene_rtc_read_time(struct device *dev, struct rtc_time *tm) ...@@ -59,11 +45,11 @@ static int xgene_rtc_read_time(struct device *dev, struct rtc_time *tm)
{ {
struct xgene_rtc_dev *pdata = dev_get_drvdata(dev); struct xgene_rtc_dev *pdata = dev_get_drvdata(dev);
rtc_time_to_tm(readl(pdata->csr_base + RTC_CCVR), tm); rtc_time64_to_tm(readl(pdata->csr_base + RTC_CCVR), tm);
return 0; return 0;
} }
static int xgene_rtc_set_mmss(struct device *dev, unsigned long secs) static int xgene_rtc_set_time(struct device *dev, struct rtc_time *tm)
{ {
struct xgene_rtc_dev *pdata = dev_get_drvdata(dev); struct xgene_rtc_dev *pdata = dev_get_drvdata(dev);
...@@ -71,7 +57,7 @@ static int xgene_rtc_set_mmss(struct device *dev, unsigned long secs) ...@@ -71,7 +57,7 @@ static int xgene_rtc_set_mmss(struct device *dev, unsigned long secs)
* NOTE: After the following write, the RTC_CCVR is only reflected * NOTE: After the following write, the RTC_CCVR is only reflected
* after the update cycle of 1 seconds. * after the update cycle of 1 seconds.
*/ */
writel((u32) secs, pdata->csr_base + RTC_CLR); writel((u32)rtc_tm_to_time64(tm), pdata->csr_base + RTC_CLR);
readl(pdata->csr_base + RTC_CLR); /* Force a barrier */ readl(pdata->csr_base + RTC_CLR); /* Force a barrier */
return 0; return 0;
...@@ -81,7 +67,8 @@ static int xgene_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) ...@@ -81,7 +67,8 @@ static int xgene_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{ {
struct xgene_rtc_dev *pdata = dev_get_drvdata(dev); struct xgene_rtc_dev *pdata = dev_get_drvdata(dev);
rtc_time_to_tm(pdata->alarm_time, &alrm->time); /* If possible, CMR should be read here */
rtc_time64_to_tm(0, &alrm->time);
alrm->enabled = readl(pdata->csr_base + RTC_CCR) & RTC_CCR_IE; alrm->enabled = readl(pdata->csr_base + RTC_CCR) & RTC_CCR_IE;
return 0; return 0;
...@@ -115,11 +102,8 @@ static int xgene_rtc_alarm_irq_enabled(struct device *dev) ...@@ -115,11 +102,8 @@ static int xgene_rtc_alarm_irq_enabled(struct device *dev)
static int xgene_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) static int xgene_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{ {
struct xgene_rtc_dev *pdata = dev_get_drvdata(dev); struct xgene_rtc_dev *pdata = dev_get_drvdata(dev);
unsigned long alarm_time;
rtc_tm_to_time(&alrm->time, &alarm_time); writel((u32)rtc_tm_to_time64(&alrm->time), pdata->csr_base + RTC_CMR);
pdata->alarm_time = alarm_time;
writel((u32) pdata->alarm_time, pdata->csr_base + RTC_CMR);
xgene_rtc_alarm_irq_enable(dev, alrm->enabled); xgene_rtc_alarm_irq_enable(dev, alrm->enabled);
...@@ -128,7 +112,7 @@ static int xgene_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) ...@@ -128,7 +112,7 @@ static int xgene_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
static const struct rtc_class_ops xgene_rtc_ops = { static const struct rtc_class_ops xgene_rtc_ops = {
.read_time = xgene_rtc_read_time, .read_time = xgene_rtc_read_time,
.set_mmss = xgene_rtc_set_mmss, .set_time = xgene_rtc_set_time,
.read_alarm = xgene_rtc_read_alarm, .read_alarm = xgene_rtc_read_alarm,
.set_alarm = xgene_rtc_set_alarm, .set_alarm = xgene_rtc_set_alarm,
.alarm_irq_enable = xgene_rtc_alarm_irq_enable, .alarm_irq_enable = xgene_rtc_alarm_irq_enable,
...@@ -136,7 +120,7 @@ static const struct rtc_class_ops xgene_rtc_ops = { ...@@ -136,7 +120,7 @@ static const struct rtc_class_ops xgene_rtc_ops = {
static irqreturn_t xgene_rtc_interrupt(int irq, void *id) static irqreturn_t xgene_rtc_interrupt(int irq, void *id)
{ {
struct xgene_rtc_dev *pdata = (struct xgene_rtc_dev *) id; struct xgene_rtc_dev *pdata = id;
/* Check if interrupt asserted */ /* Check if interrupt asserted */
if (!(readl(pdata->csr_base + RTC_STAT) & RTC_STAT_BIT)) if (!(readl(pdata->csr_base + RTC_STAT) & RTC_STAT_BIT))
...@@ -168,6 +152,10 @@ static int xgene_rtc_probe(struct platform_device *pdev) ...@@ -168,6 +152,10 @@ static int xgene_rtc_probe(struct platform_device *pdev)
if (IS_ERR(pdata->csr_base)) if (IS_ERR(pdata->csr_base))
return PTR_ERR(pdata->csr_base); return PTR_ERR(pdata->csr_base);
pdata->rtc = devm_rtc_allocate_device(&pdev->dev);
if (IS_ERR(pdata->rtc))
return PTR_ERR(pdata->rtc);
irq = platform_get_irq(pdev, 0); irq = platform_get_irq(pdev, 0);
if (irq < 0) { if (irq < 0) {
dev_err(&pdev->dev, "No IRQ resource\n"); dev_err(&pdev->dev, "No IRQ resource\n");
...@@ -198,15 +186,16 @@ static int xgene_rtc_probe(struct platform_device *pdev) ...@@ -198,15 +186,16 @@ static int xgene_rtc_probe(struct platform_device *pdev)
return ret; return ret;
} }
pdata->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
&xgene_rtc_ops, THIS_MODULE);
if (IS_ERR(pdata->rtc)) {
clk_disable_unprepare(pdata->clk);
return PTR_ERR(pdata->rtc);
}
/* HW does not support update faster than 1 seconds */ /* HW does not support update faster than 1 seconds */
pdata->rtc->uie_unsupported = 1; pdata->rtc->uie_unsupported = 1;
pdata->rtc->ops = &xgene_rtc_ops;
pdata->rtc->range_max = U32_MAX;
ret = rtc_register_device(pdata->rtc);
if (ret) {
clk_disable_unprepare(pdata->clk);
return ret;
}
return 0; return 0;
} }
......
// SPDX-License-Identifier: GPL-2.0
/* /*
* Xilinx Zynq Ultrascale+ MPSoC Real Time Clock Driver * Xilinx Zynq Ultrascale+ MPSoC Real Time Clock Driver
* *
* Copyright (C) 2015 Xilinx, Inc. * Copyright (C) 2015 Xilinx, Inc.
* *
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
*/ */
#include <linux/delay.h> #include <linux/delay.h>
......
// SPDX-License-Identifier: GPL-2.0
/* /*
* RTC subsystem, sysfs interface * RTC subsystem, sysfs interface
* *
* Copyright (C) 2005 Tower Technologies * Copyright (C) 2005 Tower Technologies
* Author: Alessandro Zummo <a.zummo@towertech.it> * Author: Alessandro Zummo <a.zummo@towertech.it>
* */
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include <linux/module.h> #include <linux/module.h>
#include <linux/rtc.h> #include <linux/rtc.h>
#include "rtc-core.h" #include "rtc-core.h"
/* device attributes */ /* device attributes */
/* /*
...@@ -86,7 +82,7 @@ max_user_freq_show(struct device *dev, struct device_attribute *attr, char *buf) ...@@ -86,7 +82,7 @@ max_user_freq_show(struct device *dev, struct device_attribute *attr, char *buf)
static ssize_t static ssize_t
max_user_freq_store(struct device *dev, struct device_attribute *attr, max_user_freq_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t n) const char *buf, size_t n)
{ {
struct rtc_device *rtc = to_rtc_device(dev); struct rtc_device *rtc = to_rtc_device(dev);
unsigned long val; unsigned long val;
...@@ -116,12 +112,11 @@ hctosys_show(struct device *dev, struct device_attribute *attr, char *buf) ...@@ -116,12 +112,11 @@ hctosys_show(struct device *dev, struct device_attribute *attr, char *buf)
{ {
#ifdef CONFIG_RTC_HCTOSYS_DEVICE #ifdef CONFIG_RTC_HCTOSYS_DEVICE
if (rtc_hctosys_ret == 0 && if (rtc_hctosys_ret == 0 &&
strcmp(dev_name(&to_rtc_device(dev)->dev), strcmp(dev_name(&to_rtc_device(dev)->dev),
CONFIG_RTC_HCTOSYS_DEVICE) == 0) CONFIG_RTC_HCTOSYS_DEVICE) == 0)
return sprintf(buf, "1\n"); return sprintf(buf, "1\n");
else
#endif #endif
return sprintf(buf, "0\n"); return sprintf(buf, "0\n");
} }
static DEVICE_ATTR_RO(hctosys); static DEVICE_ATTR_RO(hctosys);
...@@ -175,15 +170,15 @@ wakealarm_store(struct device *dev, struct device_attribute *attr, ...@@ -175,15 +170,15 @@ wakealarm_store(struct device *dev, struct device_attribute *attr,
if (*buf_ptr == '=') { if (*buf_ptr == '=') {
buf_ptr++; buf_ptr++;
push = 1; push = 1;
} else } else {
adjust = 1; adjust = 1;
}
} }
retval = kstrtos64(buf_ptr, 0, &alarm); retval = kstrtos64(buf_ptr, 0, &alarm);
if (retval) if (retval)
return retval; return retval;
if (adjust) { if (adjust)
alarm += now; alarm += now;
}
if (alarm > now || push) { if (alarm > now || push) {
/* Avoid accidentally clobbering active alarms; we can't /* Avoid accidentally clobbering active alarms; we can't
* entirely prevent that here, without even the minimal * entirely prevent that here, without even the minimal
......
/* // SPDX-License-Identifier: GPL-2.0
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
*/
#include <linux/rtc.h> #include <linux/rtc.h>
#include <linux/time.h> #include <linux/time.h>
...@@ -35,8 +30,7 @@ int rtc_set_ntp_time(struct timespec64 now, unsigned long *target_nsec) ...@@ -35,8 +30,7 @@ int rtc_set_ntp_time(struct timespec64 now, unsigned long *target_nsec)
if (!rtc) if (!rtc)
goto out_err; goto out_err;
if (!rtc->ops || (!rtc->ops->set_time && !rtc->ops->set_mmss64 && if (!rtc->ops || !rtc->ops->set_time)
!rtc->ops->set_mmss))
goto out_close; goto out_close;
/* Compute the value of tv_nsec we require the caller to supply in /* Compute the value of tv_nsec we require the caller to supply in
...@@ -58,9 +52,6 @@ int rtc_set_ntp_time(struct timespec64 now, unsigned long *target_nsec) ...@@ -58,9 +52,6 @@ int rtc_set_ntp_time(struct timespec64 now, unsigned long *target_nsec)
rtc_time64_to_tm(to_set.tv_sec, &tm); rtc_time64_to_tm(to_set.tv_sec, &tm);
/* rtc_hctosys exclusively uses UTC, so we call set_time here, not
* set_mmss.
*/
err = rtc_set_time(rtc, &tm); err = rtc_set_time(rtc, &tm);
out_close: out_close:
......
...@@ -79,8 +79,6 @@ struct rtc_class_ops { ...@@ -79,8 +79,6 @@ struct rtc_class_ops {
int (*read_alarm)(struct device *, struct rtc_wkalrm *); int (*read_alarm)(struct device *, struct rtc_wkalrm *);
int (*set_alarm)(struct device *, struct rtc_wkalrm *); int (*set_alarm)(struct device *, struct rtc_wkalrm *);
int (*proc)(struct device *, struct seq_file *); int (*proc)(struct device *, struct seq_file *);
int (*set_mmss64)(struct device *, time64_t secs);
int (*set_mmss)(struct device *, unsigned long secs);
int (*alarm_irq_enable)(struct device *, unsigned int enabled); int (*alarm_irq_enable)(struct device *, unsigned int enabled);
int (*read_offset)(struct device *, long *offset); int (*read_offset)(struct device *, long *offset);
int (*set_offset)(struct device *, long offset); int (*set_offset)(struct device *, long offset);
...@@ -162,9 +160,11 @@ struct rtc_device { ...@@ -162,9 +160,11 @@ struct rtc_device {
#define to_rtc_device(d) container_of(d, struct rtc_device, dev) #define to_rtc_device(d) container_of(d, struct rtc_device, dev)
/* useful timestamps */ /* useful timestamps */
#define RTC_TIMESTAMP_BEGIN_1900 -2208989361LL /* 1900-01-01 00:00:00 */ #define RTC_TIMESTAMP_BEGIN_1900 -2208988800LL /* 1900-01-01 00:00:00 */
#define RTC_TIMESTAMP_BEGIN_2000 946684800LL /* 2000-01-01 00:00:00 */ #define RTC_TIMESTAMP_BEGIN_2000 946684800LL /* 2000-01-01 00:00:00 */
#define RTC_TIMESTAMP_END_2063 2966371199LL /* 2063-12-31 23:59:59 */
#define RTC_TIMESTAMP_END_2099 4102444799LL /* 2099-12-31 23:59:59 */ #define RTC_TIMESTAMP_END_2099 4102444799LL /* 2099-12-31 23:59:59 */
#define RTC_TIMESTAMP_END_9999 253402300799LL /* 9999-12-31 23:59:59 */
extern struct rtc_device *devm_rtc_device_register(struct device *dev, extern struct rtc_device *devm_rtc_device_register(struct device *dev,
const char *name, const char *name,
......
...@@ -48,8 +48,6 @@ struct ds1685_priv { ...@@ -48,8 +48,6 @@ struct ds1685_priv {
u32 regstep; u32 regstep;
resource_size_t baseaddr; resource_size_t baseaddr;
size_t size; size_t size;
spinlock_t lock;
struct work_struct work;
int irq_num; int irq_num;
bool bcd_mode; bool bcd_mode;
bool no_irq; bool no_irq;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment