summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2021-12-15 18:54:58 +0100
committerAlexandre Belloni <alexandre.belloni@bootlin.com>2021-12-16 10:46:35 +0100
commit322539a014bcd24cbb9281832c09b24e07912237 (patch)
tree6c3c8b22747a16192c533e58e6b787f887a8951d /drivers
parentrtc: gamecube: Add a RTC driver for the GameCube, Wii and Wii U (diff)
downloadlinux-322539a014bcd24cbb9281832c09b24e07912237.tar.xz
linux-322539a014bcd24cbb9281832c09b24e07912237.zip
rtc: gamecube: Report low battery as invalid data
I haven’t been able to test this patch as all of my consoles have a working RTC battery, but according to the documentation it should work like that. Signed-off-by: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> Acked-by: Michael Ellerman <mpe@ellerman.id.au> (powerpc) Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Link: https://lore.kernel.org/r/20211215175501.6761-3-linkmauve@linkmauve.fr
Diffstat (limited to 'drivers')
-rw-r--r--drivers/rtc/rtc-gamecube.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/drivers/rtc/rtc-gamecube.c b/drivers/rtc/rtc-gamecube.c
index e8260c82c07d..98128746171e 100644
--- a/drivers/rtc/rtc-gamecube.c
+++ b/drivers/rtc/rtc-gamecube.c
@@ -83,6 +83,10 @@
#define RTC_CONTROL0 0x21000c
#define RTC_CONTROL1 0x21000d
+/* RTC flags */
+#define RTC_CONTROL0_UNSTABLE_POWER 0x00000800
+#define RTC_CONTROL0_LOW_BATTERY 0x00000200
+
struct priv {
struct regmap *regmap;
void __iomem *iob;
@@ -182,9 +186,35 @@ static int gamecube_rtc_set_time(struct device *dev, struct rtc_time *t)
return regmap_write(d->regmap, RTC_COUNTER, timestamp - d->rtc_bias);
}
+static int gamecube_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
+{
+ struct priv *d = dev_get_drvdata(dev);
+ int value;
+ int control0;
+ int ret;
+
+ switch (cmd) {
+ case RTC_VL_READ:
+ ret = regmap_read(d->regmap, RTC_CONTROL0, &control0);
+ if (ret)
+ return ret;
+
+ value = 0;
+ if (control0 & RTC_CONTROL0_UNSTABLE_POWER)
+ value |= RTC_VL_DATA_INVALID;
+ if (control0 & RTC_CONTROL0_LOW_BATTERY)
+ value |= RTC_VL_BACKUP_LOW;
+ return put_user(value, (unsigned int __user *)arg);
+
+ default:
+ return -ENOIOCTLCMD;
+ }
+}
+
static const struct rtc_class_ops gamecube_rtc_ops = {
.read_time = gamecube_rtc_read_time,
.set_time = gamecube_rtc_set_time,
+ .ioctl = gamecube_rtc_ioctl,
};
static int gamecube_rtc_read_offset_from_sram(struct priv *d)