mbox series

[0/3] Add RTC for MStar SSD20xD SoCs

Message ID 20230517144144.365631-1-romain.perier@gmail.com
Headers show
Series Add RTC for MStar SSD20xD SoCs | expand

Message

Romain Perier May 17, 2023, 2:41 p.m. UTC
This patches series adds a new driver for the RTC found in the Mstar
SSD20xD SoCs. It adds a basic rtc driver, the corresponding devicetree
bindings and its documentation.

The rtctest (from selftests) has been passed on this driver, with the
following output:

# rtctest 
TAP version 13
1..8
# Starting 8 tests from 1 test cases.
#  RUN           rtc.date_read ...
# rtctest.c:52:date_read:Current RTC date/time is 17/05/2023 15:58:12.
#            OK  rtc.date_read
ok 1 rtc.date_read
#  RUN           rtc.date_read_loop ...
# rtctest.c:95:date_read_loop:Continuously reading RTC time for 30s (with 11ms breaks after every read).
# rtctest.c:122:date_read_loop:Performed 888 RTC time reads.
#            OK  rtc.date_read_loop
ok 2 rtc.date_read_loop
#  RUN           rtc.uie_read ...
# rtctest.c:137:uie_read:skip update IRQs not supported.
#            OK  rtc.uie_read
ok 3 rtc.uie_read
#  RUN           rtc.uie_select ...
# rtctest.c:166:uie_select:skip update IRQs not supported.
#            OK  rtc.uie_select
ok 4 rtc.uie_select
#  RUN           rtc.alarm_alm_set ...
# rtctest.c:214:alarm_alm_set:skip alarms are not supported.
#            OK  rtc.alarm_alm_set
ok 5 rtc.alarm_alm_set
#  RUN           rtc.alarm_wkalm_set ...
# rtctest.c:274:alarm_wkalm_set:skip alarms are not supported.
#            OK  rtc.alarm_wkalm_set
ok 6 rtc.alarm_wkalm_set
#  RUN           rtc.alarm_alm_set_minute ...
# rtctest.c:324:alarm_alm_set_minute:skip alarms are not supported.
#            OK  rtc.alarm_alm_set_minute
ok 7 rtc.alarm_alm_set_minute
#  RUN           rtc.alarm_wkalm_set_minute ...
# rtctest.c:384:alarm_wkalm_set_minute:skip alarms are not supported.
#            OK  rtc.alarm_wkalm_set_minute
ok 8 rtc.alarm_wkalm_set_minute
# PASSED: 8 / 8 tests passed.
# Totals: pass:8 fail:0 xfail:0 xpass:0 skip:0 error:0


Romain Perier (3):
  rtc: Add support for the SSD20xD RTC
  dt-bindings: rtc: Add Mstar SSD20xD RTC devicetree bindings
    documentation
  ARM: dts: mstar: Enable rtc for SSD20xD

 .../bindings/rtc/mstar,ssd20xd-rtc.yaml       |  37 +++
 arch/arm/boot/dts/mstar-infinity2m.dtsi       |   5 +
 drivers/rtc/Kconfig                           |  11 +
 drivers/rtc/Makefile                          |   1 +
 drivers/rtc/rtc-ssd20xd.c                     | 249 ++++++++++++++++++
 5 files changed, 303 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/mstar,ssd20xd-rtc.yaml
 create mode 100644 drivers/rtc/rtc-ssd20xd.c

Comments

Alexandre Belloni May 29, 2023, 10:40 p.m. UTC | #1
Hello,

On 17/05/2023 16:41:42+0200, Romain Perier wrote:
> Newer SigmaStar SSD20xD SoCs contain a really low power RTC (300uA claimed),

The low power RTCs are more on the side of a few tenth of nA. RV3028
consumes 40nA, including the crystal. AB1805 consumes 14nA with an RC
oscillator. It is funny how SoC vendors think they are low power ;)

> +static int ssd20xd_rtc_isoctrl(struct ssd20xd_rtc *priv)
> +{
> +	static const unsigned int sequence[] = { 0x0, 0x1, 0x3, 0x7, 0x5, 0x1, 0x0 };
> +	unsigned int val;
> +	struct device *dev = &priv->rtc_dev->dev;
> +	int i, ret;
> +
> +	/*
> +	 * This gates iso_en by writing a special sequence of bytes to iso_ctrl
> +	 * and ensuring that it has been correctly applied by reading iso_ctrl_ack
> +	 */
> +	for (i = 0; i < ARRAY_SIZE(sequence); i++) {
> +		writeb(sequence[i] & ISO_CTRL_MASK, priv->base +  REG_ISO_CTRL);
> +
> +		ret = read_poll_timeout(read_iso_ctrl_ack, val, val == (i % 2), 100,
> +					20 * 100, true, priv->base);
> +		if (ret) {
> +			dev_err(dev, "Timeout waiting for ack byte %i (%x) of sequence\n", i,
> +				sequence[i]);

This is a user visible message but there is no action for the user to
take apart from retrying. You should drop this.

> +			return ret;
> +		}
> +	}
> +
> +	/*
> +	 * At this point iso_en should be raised for 1ms
> +	 */
> +	ret = read_poll_timeout(read_iso_en, val, val, 100, 22 * 100, true, priv->base);
> +	if (ret)
> +		dev_err(dev, "Timeout waiting for iso_en\n");

Ditto.

> +	mdelay(2);
> +	return 0;
> +}
> +
Daniel Palmer May 29, 2023, 11:06 p.m. UTC | #2
Hi Alexandre,

On Tue, 30 May 2023 at 07:40, Alexandre Belloni
<alexandre.belloni@bootlin.com> wrote:
>
> Hello,
>
> On 17/05/2023 16:41:42+0200, Romain Perier wrote:
> > Newer SigmaStar SSD20xD SoCs contain a really low power RTC (300uA claimed),
>
> The low power RTCs are more on the side of a few tenth of nA. RV3028
> consumes 40nA, including the crystal. AB1805 consumes 14nA with an RC
> oscillator. It is funny how SoC vendors think they are low power ;)

To be fair to them I think the 300uA claim is for the whole SoC in
RTC-only deep sleep.
Whatever logic is powered on alongside the RTC to trigger wake up will
be part of that number I guess.

Cheers,

Daniel