Skip to content

Commit

Permalink
MIPS: PS2: SCMD: Write system real-time clock (RTC) command
Browse files Browse the repository at this point in the history
Signed-off-by: Fredrik Noring <noring@nocrew.org>
  • Loading branch information
frno7 committed May 13, 2019
1 parent 80440b3 commit 02cc773
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions arch/mips/include/asm/mach-ps2/scmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@ struct scmd_machine_name scmd_read_machine_name(void);
/* System command to read the real-time clock (RTC). */
int scmd_read_rtc(time64_t *t);

/* System command to write the real-time clock (RTC). */
int scmd_write_rtc(time64_t t);

#endif /* __ASM_PS2_SCMD_H */
40 changes: 40 additions & 0 deletions arch/mips/ps2/scmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,46 @@ int scmd_read_rtc(time64_t *t)
}
EXPORT_SYMBOL_GPL(scmd_read_rtc);

int scmd_write_rtc(time64_t t)
{
struct __attribute__ ((packed)) {
u8 second;
u8 minute;
u8 hour;
u8 pad;
u8 day;
u8 month;
u8 year;
} rtc = { };
struct rtc_time tm;
u8 status;
int err;

rtc_time_to_tm(t + UTC_TO_JST, &tm);
rtc.second = bin2bcd(tm.tm_sec);
rtc.minute = bin2bcd(tm.tm_min);
rtc.hour = bin2bcd(tm.tm_hour);
rtc.day = bin2bcd(tm.tm_mday);
rtc.month = bin2bcd(tm.tm_mon + 1);
rtc.year = bin2bcd(tm.tm_year - 100);

BUILD_BUG_ON(sizeof(rtc) != 7);
err = scmd(0x9, &rtc, sizeof(rtc), &status, sizeof(status));
if (err < 0) {
pr_debug("%s: Write failed with %d\n", __func__, err);
return err;
}

if (status != 0) {
pr_debug("%s: Invalid result with status 0x%x\n",
__func__, status);
return -EIO;
}

return 0;
}
EXPORT_SYMBOL_GPL(scmd_write_rtc);

MODULE_DESCRIPTION("PlayStation 2 system command driver");
MODULE_AUTHOR("Fredrik Noring");
MODULE_LICENSE("GPL");

0 comments on commit 02cc773

Please sign in to comment.