From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
Cc: "Alessandro Zummo" <a.zummo@towertech.it>,
rw-r-r-0644 <r.r.qwertyuiop.r.r@gmail.com>,
"Ash Logan" <ash@heyquark.com>,
"Jonathan Neuschäfer" <j.ne@posteo.net>,
linux-kernel@vger.kernel.org, linux-rtc@vger.kernel.org
Subject: Re: [PATCH] rtc: nintendo: Add a RTC driver for the GameCube, Wii and Wii U
Date: Wed, 27 Oct 2021 22:32:53 +0200 [thread overview]
Message-ID: <YXm3da9Mq8HR3Iin@piout.net> (raw)
In-Reply-To: <20211027170527.za6xlwvmzmulgqoa@luna>
On 27/10/2021 19:05:27+0200, Emmanuel Gil Peyrot wrote:
> > On 15/10/2021 00:05:24+0200, Emmanuel Gil Peyrot wrote:
> > > These three consoles share a device, the MX23L4005, which contains a
> > > clock and 64 bytes of SRAM storage, and is exposed on the EXI bus
> > > (similar to SPI) on channel 0, device 1. This driver allows it to be
> > > used as a Linux RTC device, where time can be read and set.
> > >
> > > The hardware also exposes two timers, one which shuts down the console
> > > and one which powers it on, but these aren’t supported currently.
> > >
> > > On the Wii U, the counter bias is stored in a XML file, /config/rtc.xml,
> > > encrypted in the SLC (eMMC storage), using a proprietary filesystem. In
> > > order to avoid having to implement all that, this driver assumes a
> > > bootloader will parse this XML file and write the bias into the SRAM, at
> > > the same location the other two consoles have it.
> > >
> > > Signed-off-by: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
> > > ---
> > > drivers/rtc/Kconfig | 10 ++
> > > drivers/rtc/Makefile | 1 +
> > > drivers/rtc/rtc-nintendo.c | 305 +++++++++++++++++++++++++++++++++++++
> >
> > I'm not convinced this is a good name, seeing that the switch will
> > certainly not use this driver (neither is the snes mini).
>
> Other subsystem maintainers have requested this to be changed, so I
> reflected it here too. For instance hid requested a Wii U-specific
> driver to be merged with the Switch one.
>
> Would rtc-gamecube be fine then? So far I have only tested on Wii U,
> but this driver is expected to support all three generations of
> GameCube, Wii and Wii U.
>
I think this is appropriate, that would have been my suggestion.
> > > +static int nintendo_rtc_set_time(struct device *dev, struct rtc_time *t)
> > > +{
> > > + time64_t timestamp;
> > > + struct nintendo_rtc_drvdata *d = dev_get_drvdata(dev);
> > > +
> > > + /* Subtract the timestamp and the bias to obtain the counter value */
> > > + timestamp = rtc_tm_to_time64(t);
> > > + exi_write(d->iob, RTC_COUNTER, timestamp - d->rtc_bias);
> >
> > As you are able to update RTC_COUNTER, I'm not sure why you actually
> > need rtc_bias.
>
> The proprietary firmware sets the counter based on the bias, so if we
> want to get the correct time out of the box we have to sum them. It
> wouldn’t even be possible to set bias on all of the consoles from Linux,
> for instance on the Wii U it is stored in an XML file, in a proprietary
> filesystem, and encrypted (using keys for which the drivers are already
> in mainline at least).
>
Ok, fine by me.
> > > +#ifdef DEBUG
> > > +static void nintendo_rtc_dumpregs(void __iomem *iob)
> > > +{
> > > + int i;
> > > + u32 sram_addr = RTC_SRAM;
> > > +
> > > + printk("RTC_COUNTER: %08X\n", exi_read(iob, RTC_COUNTER));
> > > + printk("RTC_SNAPSHOT: %08X\n", exi_read(iob, RTC_SNAPSHOT));
> > > + printk("RTC_ONTMR: %08X\n", exi_read(iob, RTC_ONTMR));
> > > + printk("RTC_OFFTMR: %08X\n", exi_read(iob, RTC_OFFTMR));
> > > + printk("RTC_TEST0: %08X\n", exi_read(iob, RTC_TEST0));
> > > + printk("RTC_TEST1: %08X\n", exi_read(iob, RTC_TEST1));
> > > + printk("RTC_TEST2: %08X\n", exi_read(iob, RTC_TEST2));
> > > + printk("RTC_TEST3: %08X\n", exi_read(iob, RTC_TEST3));
> > > + printk("RTC_CONTROL0: %08X\n", exi_read(iob, RTC_CONTROL0));
> > > + printk("RTC_CONTROL1: %08X\n", exi_read(iob, RTC_CONTROL1));
> > > + printk("RTC_SRAM:\n");
> > > + for(i = 0; i < 4; i++) {
> > > + printk("%08X %08X %08X %08X\n",
> > > + exi_read(iob, sram_addr + 0x100 * 0),
> > > + exi_read(iob, sram_addr + 0x100 * 1),
> > > + exi_read(iob, sram_addr + 0x100 * 2),
> > > + exi_read(iob, sram_addr + 0x100 * 3));
> > > + sram_addr += 0x400;
> >
> > Something great to do would be to convert the driver to regmap, provding
> > custom regmap_read and regmap_write functions to access the EXI bus.
> > Then you'd get this directly in debugfs. And this could be split ou once
> > other drivers need access to the bus (I guess power/reset at some
> > point).
>
> Will do, I wasn’t aware of regmap, thanks!
>
This is feature creep pushed to the max, I would take your driver even
if you don't do that.
> >
> > Ideally, you should also expose LOW_BATT from RTC_CONTROL0 using the
> > VL_READ ioctl as I'm guessing many console will start to have a depleted
> > battery.
>
> I won’t be able to test that yet, but I’ll try to implement it as it is
> documented.
>
This can also come in a second patch. I'll try to boot up my own
(platinum edition) GC, I'm wondering what is the battery status :)
--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
next prev parent reply other threads:[~2021-10-27 20:32 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-14 22:05 [PATCH] rtc: nintendo: Add a RTC driver for the GameCube, Wii and Wii U Emmanuel Gil Peyrot
2021-10-27 16:45 ` Alexandre Belloni
2021-10-27 17:05 ` Emmanuel Gil Peyrot
2021-10-27 17:09 ` Emmanuel Gil Peyrot
2021-10-27 20:32 ` Alexandre Belloni [this message]
2021-10-28 20:32 ` Jonathan Neuschäfer
2021-10-28 21:34 ` Emmanuel Gil Peyrot
2021-10-29 11:06 ` Jonathan Neuschäfer
2021-10-27 22:35 ` [PATCH v2 0/5] " Emmanuel Gil Peyrot
2021-10-27 22:35 ` [PATCH v2 1/5] rtc: gamecube: " Emmanuel Gil Peyrot
2021-10-27 22:35 ` [PATCH v2 2/5] rtc: gamecube: Report low battery as invalid data Emmanuel Gil Peyrot
2021-11-30 22:45 ` Alexandre Belloni
2021-12-15 17:52 ` Emmanuel Gil Peyrot
2021-10-27 22:35 ` [PATCH v2 3/5] powerpc: wii.dts: Expose HW_SRNPROT on this platform Emmanuel Gil Peyrot
2021-10-27 22:35 ` [PATCH v2 4/5] powerpc: gamecube_defconfig: Enable the RTC driver Emmanuel Gil Peyrot
2021-10-27 22:35 ` [PATCH v2 5/5] powerpc: wii_defconfig: " Emmanuel Gil Peyrot
2021-12-15 17:54 ` [PATCH v3 0/5] rtc: nintendo: Add a RTC driver for the GameCube, Wii and Wii U Emmanuel Gil Peyrot
2021-12-15 17:54 ` [PATCH v3 1/5] rtc: gamecube: " Emmanuel Gil Peyrot
2021-12-15 17:54 ` [PATCH v3 2/5] rtc: gamecube: Report low battery as invalid data Emmanuel Gil Peyrot
2021-12-15 17:54 ` [PATCH v3 3/5] powerpc: wii.dts: Expose HW_SRNPROT on this platform Emmanuel Gil Peyrot
2021-12-15 17:55 ` [PATCH v3 4/5] powerpc: gamecube_defconfig: Enable the RTC driver Emmanuel Gil Peyrot
2021-12-15 17:55 ` [PATCH v3 5/5] powerpc: wii_defconfig: " Emmanuel Gil Peyrot
2021-12-16 4:52 ` [PATCH v3 0/5] rtc: nintendo: Add a RTC driver for the GameCube, Wii and Wii U Michael Ellerman
2021-12-16 9:50 ` Alexandre Belloni
2021-12-16 9:49 ` Alexandre Belloni
2021-12-16 20:22 ` Emmanuel Gil Peyrot
2021-12-16 20:56 ` Alexandre Belloni
2021-12-16 20:58 ` Emmanuel Gil Peyrot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YXm3da9Mq8HR3Iin@piout.net \
--to=alexandre.belloni@bootlin.com \
--cc=a.zummo@towertech.it \
--cc=ash@heyquark.com \
--cc=j.ne@posteo.net \
--cc=linkmauve@linkmauve.fr \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rtc@vger.kernel.org \
--cc=r.r.qwertyuiop.r.r@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).