#include <linux/arm-smccc.h>
#include <linux/firmware/imx/sci.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#define IMX_SC_TIMER_FUNC_GET_RTC_SEC1970 9
#define IMX_SC_TIMER_FUNC_SET_RTC_TIME 6
#define IMX_SIP_SRTC 0xC2000002
#define IMX_SIP_SRTC_SET_TIME 0x0
static struct imx_sc_ipc *rtc_ipc_handle;
static struct rtc_device *imx_sc_rtc;
struct imx_sc_msg_timer_get_rtc_time {
struct imx_sc_rpc_msg hdr;
static int imx_sc_rtc_read_time(struct device *dev, struct rtc_time *tm)
struct imx_sc_msg_timer_get_rtc_time msg;
struct imx_sc_rpc_msg *hdr = &msg.hdr;
hdr->ver = IMX_SC_RPC_VERSION;
hdr->svc = IMX_SC_RPC_SVC_TIMER;
hdr->func = IMX_SC_TIMER_FUNC_GET_RTC_SEC1970;
ret = imx_scu_call_rpc(rtc_ipc_handle, &msg, true);
dev_err(dev, "read rtc time failed, ret %d\n", ret);
rtc_time64_to_tm(msg.time, tm);
static int imx_sc_rtc_set_time(struct device *dev, struct rtc_time *tm)
struct arm_smccc_res res;
arm_smccc_smc(IMX_SIP_SRTC, IMX_SIP_SRTC_SET_TIME,
((tm->tm_year + 1900) << 16) | (tm->tm_mon + 1),
(tm->tm_mday << 16) | tm->tm_hour,
(tm->tm_min << 16) | tm->tm_sec,
static const struct rtc_class_ops imx_sc_rtc_ops = {