All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] rtc: Implement support for EPSON RX-8035
@ 2021-07-09  4:45 Mathew McBride
  2021-07-09  4:45 ` [PATCH v2 1/2] rtc: rx8025: implement RX-8035 support Mathew McBride
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Mathew McBride @ 2021-07-09  4:45 UTC (permalink / raw)
  To: linux-rtc, Alessandro Zummo, Alexandre Belloni, Rob Herring, devicetree
  Cc: Mathew McBride

The EPSON RX-8035[SA] is a I2C real time clock module with
built-in oscillator[1]. It is a very close relative of the EPSON
RX-8025 that is supported by the rtc-rx8025 driver.

The main difference is that the RX-8035 has inverted the
'oscillator stop' bit in the control register. The operation
of the devices is otherwise identical for the features currently
supported.

Curiously, the RX-8025 is also supported by the ds1307 driver
as the time register set is compatible. The control registers,
however, are not.

I have decided to implement the RX-8035 in rtc-rx8025 due the simplicity
of that driver.

As best as I can determine, the rtc-rx8025 driver was in the tree
some months[1] before rx8025 support was added to ds1307[2].

[1] - https://www5.epsondevice.com/en/products/rtc/rx8035sa.html
[2] - commit 3c2b9075cbdb541dbe486bde45925c9610de6f35
[3] - commit a216685818a54b4f15235068b53908f954850251

Changes in v2:
Coding style fixes as per suggestions
Use 'model' instead of 'type' in drvdata
Call rx8025_is_osc_stopped in a consistent manner

Mathew McBride (2):
  rtc: rx8025: implement RX-8035 support
  dt-bindings: rtc: add Epson RX-8025 and RX-8035

 .../devicetree/bindings/rtc/trivial-rtc.yaml  |  3 +
 drivers/rtc/rtc-rx8025.c                      | 59 +++++++++++++++++--
 2 files changed, 57 insertions(+), 5 deletions(-)

-- 
2.30.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/2] rtc: rx8025: implement RX-8035 support
  2021-07-09  4:45 [PATCH v2 0/2] rtc: Implement support for EPSON RX-8035 Mathew McBride
@ 2021-07-09  4:45 ` Mathew McBride
  2021-07-19  8:15   ` Nobuhiro Iwamatsu
  2021-07-09  4:45 ` [PATCH v2 2/2] dt-bindings: rtc: add Epson RX-8025 and RX-8035 Mathew McBride
  2021-08-17 22:08 ` [PATCH v2 0/2] rtc: Implement support for EPSON RX-8035 Alexandre Belloni
  2 siblings, 1 reply; 7+ messages in thread
From: Mathew McBride @ 2021-07-09  4:45 UTC (permalink / raw)
  To: linux-rtc, Alessandro Zummo, Alexandre Belloni, Rob Herring, devicetree
  Cc: Mathew McBride

The RX-8035 is a newer RTC from EPSON that is very
similar to the RX-8025.

The key difference is in the oscillation stop (XSTP)
bit which is inverted on the RX-8035.

Signed-off-by: Mathew McBride <matt@traverse.com.au>
---
 drivers/rtc/rtc-rx8025.c | 58 ++++++++++++++++++++++++++++++++++++----
 1 file changed, 53 insertions(+), 5 deletions(-)

diff --git a/drivers/rtc/rtc-rx8025.c b/drivers/rtc/rtc-rx8025.c
index c914091819ba..7a0258fe4b8e 100644
--- a/drivers/rtc/rtc-rx8025.c
+++ b/drivers/rtc/rtc-rx8025.c
@@ -60,14 +60,23 @@
 #define RX8025_ADJ_DATA_MAX	62
 #define RX8025_ADJ_DATA_MIN	-62
 
+enum rx_model {
+	model_rx_unknown,
+	model_rx_8025,
+	model_rx_8035,
+	model_last
+};
+
 static const struct i2c_device_id rx8025_id[] = {
-	{ "rx8025", 0 },
+	{ "rx8025", model_rx_8025 },
+	{ "rx8035", model_rx_8035 },
 	{ }
 };
 MODULE_DEVICE_TABLE(i2c, rx8025_id);
 
 struct rx8025_data {
 	struct rtc_device *rtc;
+	enum rx_model model;
 	u8 ctrl1;
 };
 
@@ -100,10 +109,26 @@ static s32 rx8025_write_regs(const struct i2c_client *client,
 					      length, values);
 }
 
+static int rx8025_is_osc_stopped(enum rx_model model, int ctrl2)
+{
+	int xstp = ctrl2 & RX8025_BIT_CTRL2_XST;
+	/* XSTP bit has different polarity on RX-8025 vs RX-8035.
+	 * RX-8025: 0 == oscillator stopped
+	 * RX-8035: 1 == oscillator stopped
+	 */
+
+	if (model == model_rx_8025)
+		xstp = !xstp;
+
+	return xstp;
+}
+
 static int rx8025_check_validity(struct device *dev)
 {
 	struct i2c_client *client = to_i2c_client(dev);
+	struct rx8025_data *drvdata = dev_get_drvdata(dev);
 	int ctrl2;
+	int xstp;
 
 	ctrl2 = rx8025_read_reg(client, RX8025_REG_CTRL2);
 	if (ctrl2 < 0)
@@ -117,7 +142,8 @@ static int rx8025_check_validity(struct device *dev)
 		return -EINVAL;
 	}
 
-	if (!(ctrl2 & RX8025_BIT_CTRL2_XST)) {
+	xstp = rx8025_is_osc_stopped(drvdata->model, ctrl2);
+	if (xstp) {
 		dev_warn(dev, "crystal stopped, date is invalid\n");
 		return -EINVAL;
 	}
@@ -127,6 +153,7 @@ static int rx8025_check_validity(struct device *dev)
 
 static int rx8025_reset_validity(struct i2c_client *client)
 {
+	struct rx8025_data *drvdata = i2c_get_clientdata(client);
 	int ctrl2 = rx8025_read_reg(client, RX8025_REG_CTRL2);
 
 	if (ctrl2 < 0)
@@ -134,22 +161,28 @@ static int rx8025_reset_validity(struct i2c_client *client)
 
 	ctrl2 &= ~(RX8025_BIT_CTRL2_PON | RX8025_BIT_CTRL2_VDET);
 
+	if (drvdata->model == model_rx_8025)
+		ctrl2 |= RX8025_BIT_CTRL2_XST;
+	else
+		ctrl2 &= ~(RX8025_BIT_CTRL2_XST);
+
 	return rx8025_write_reg(client, RX8025_REG_CTRL2,
-				ctrl2 | RX8025_BIT_CTRL2_XST);
+				ctrl2);
 }
 
 static irqreturn_t rx8025_handle_irq(int irq, void *dev_id)
 {
 	struct i2c_client *client = dev_id;
 	struct rx8025_data *rx8025 = i2c_get_clientdata(client);
-	int status;
+	int status, xstp;
 
 	rtc_lock(rx8025->rtc);
 	status = rx8025_read_reg(client, RX8025_REG_CTRL2);
 	if (status < 0)
 		goto out;
 
-	if (!(status & RX8025_BIT_CTRL2_XST))
+	xstp = rx8025_is_osc_stopped(rx8025->model, status);
+	if (xstp)
 		dev_warn(&client->dev, "Oscillation stop was detected,"
 			 "you may have to readjust the clock\n");
 
@@ -519,6 +552,21 @@ static int rx8025_probe(struct i2c_client *client,
 
 	i2c_set_clientdata(client, rx8025);
 
+	if (id) {
+		rx8025->model = id->driver_data;
+		switch (rx8025->model) {
+		case model_rx_8025:
+			dev_info(&client->dev, "Model RX-8025");
+			break;
+		case model_rx_8035:
+			dev_info(&client->dev, "Model RX-8035");
+			break;
+		default:
+			dev_warn(&client->dev, "Unknown model: %d\n", rx8025->model);
+			break;
+		}
+	}
+
 	err = rx8025_init_client(client);
 	if (err)
 		return err;
-- 
2.30.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 2/2] dt-bindings: rtc: add Epson RX-8025 and RX-8035
  2021-07-09  4:45 [PATCH v2 0/2] rtc: Implement support for EPSON RX-8035 Mathew McBride
  2021-07-09  4:45 ` [PATCH v2 1/2] rtc: rx8025: implement RX-8035 support Mathew McBride
@ 2021-07-09  4:45 ` Mathew McBride
  2021-07-14 23:15   ` Rob Herring
  2021-07-19  8:18   ` Nobuhiro Iwamatsu
  2021-08-17 22:08 ` [PATCH v2 0/2] rtc: Implement support for EPSON RX-8035 Alexandre Belloni
  2 siblings, 2 replies; 7+ messages in thread
From: Mathew McBride @ 2021-07-09  4:45 UTC (permalink / raw)
  To: linux-rtc, Alessandro Zummo, Alexandre Belloni, Rob Herring, devicetree
  Cc: Mathew McBride

These are supported by the rtc-rx8025 module. RX-8025
also has support in ds1307 due to compatible time registers.

Signed-off-by: Mathew McBride <matt@traverse.com.au>
---
 Documentation/devicetree/bindings/rtc/trivial-rtc.yaml | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/Documentation/devicetree/bindings/rtc/trivial-rtc.yaml b/Documentation/devicetree/bindings/rtc/trivial-rtc.yaml
index 7548d8714871..13925bb78ec7 100644
--- a/Documentation/devicetree/bindings/rtc/trivial-rtc.yaml
+++ b/Documentation/devicetree/bindings/rtc/trivial-rtc.yaml
@@ -32,6 +32,9 @@ properties:
       - dallas,ds3232
       # I2C-BUS INTERFACE REAL TIME CLOCK MODULE
       - epson,rx8010
+      # I2C-BUS INTERFACE REAL TIME CLOCK MODULE
+      - epson,rx8025
+      - epson,rx8035
       # I2C-BUS INTERFACE REAL TIME CLOCK MODULE with Battery Backed RAM
       - epson,rx8571
       # I2C-BUS INTERFACE REAL TIME CLOCK MODULE
-- 
2.30.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/2] dt-bindings: rtc: add Epson RX-8025 and RX-8035
  2021-07-09  4:45 ` [PATCH v2 2/2] dt-bindings: rtc: add Epson RX-8025 and RX-8035 Mathew McBride
@ 2021-07-14 23:15   ` Rob Herring
  2021-07-19  8:18   ` Nobuhiro Iwamatsu
  1 sibling, 0 replies; 7+ messages in thread
From: Rob Herring @ 2021-07-14 23:15 UTC (permalink / raw)
  To: Mathew McBride
  Cc: Alexandre Belloni, Rob Herring, Alessandro Zummo, linux-rtc, devicetree

On Fri, 09 Jul 2021 04:45:18 +0000, Mathew McBride wrote:
> These are supported by the rtc-rx8025 module. RX-8025
> also has support in ds1307 due to compatible time registers.
> 
> Signed-off-by: Mathew McBride <matt@traverse.com.au>
> ---
>  Documentation/devicetree/bindings/rtc/trivial-rtc.yaml | 3 +++
>  1 file changed, 3 insertions(+)
> 

Acked-by: Rob Herring <robh@kernel.org>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/2] rtc: rx8025: implement RX-8035 support
  2021-07-09  4:45 ` [PATCH v2 1/2] rtc: rx8025: implement RX-8035 support Mathew McBride
@ 2021-07-19  8:15   ` Nobuhiro Iwamatsu
  0 siblings, 0 replies; 7+ messages in thread
From: Nobuhiro Iwamatsu @ 2021-07-19  8:15 UTC (permalink / raw)
  To: Mathew McBride
  Cc: linux-rtc, Alessandro Zummo, Alexandre Belloni, Rob Herring, devicetree

Hi,

2021年7月9日(金) 13:45 Mathew McBride <matt@traverse.com.au>:
>
> The RX-8035 is a newer RTC from EPSON that is very
> similar to the RX-8025.
>
> The key difference is in the oscillation stop (XSTP)
> bit which is inverted on the RX-8035.
>
> Signed-off-by: Mathew McBride <matt@traverse.com.au>

Reviewed- by: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>

Best regards,
  Nobuhiro

> ---
>  drivers/rtc/rtc-rx8025.c | 58 ++++++++++++++++++++++++++++++++++++----
>  1 file changed, 53 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/rtc/rtc-rx8025.c b/drivers/rtc/rtc-rx8025.c
> index c914091819ba..7a0258fe4b8e 100644
> --- a/drivers/rtc/rtc-rx8025.c
> +++ b/drivers/rtc/rtc-rx8025.c
> @@ -60,14 +60,23 @@
>  #define RX8025_ADJ_DATA_MAX    62
>  #define RX8025_ADJ_DATA_MIN    -62
>
> +enum rx_model {
> +       model_rx_unknown,
> +       model_rx_8025,
> +       model_rx_8035,
> +       model_last
> +};
> +
>  static const struct i2c_device_id rx8025_id[] = {
> -       { "rx8025", 0 },
> +       { "rx8025", model_rx_8025 },
> +       { "rx8035", model_rx_8035 },
>         { }
>  };
>  MODULE_DEVICE_TABLE(i2c, rx8025_id);
>
>  struct rx8025_data {
>         struct rtc_device *rtc;
> +       enum rx_model model;
>         u8 ctrl1;
>  };
>
> @@ -100,10 +109,26 @@ static s32 rx8025_write_regs(const struct i2c_client *client,
>                                               length, values);
>  }
>
> +static int rx8025_is_osc_stopped(enum rx_model model, int ctrl2)
> +{
> +       int xstp = ctrl2 & RX8025_BIT_CTRL2_XST;
> +       /* XSTP bit has different polarity on RX-8025 vs RX-8035.
> +        * RX-8025: 0 == oscillator stopped
> +        * RX-8035: 1 == oscillator stopped
> +        */
> +
> +       if (model == model_rx_8025)
> +               xstp = !xstp;
> +
> +       return xstp;
> +}
> +
>  static int rx8025_check_validity(struct device *dev)
>  {
>         struct i2c_client *client = to_i2c_client(dev);
> +       struct rx8025_data *drvdata = dev_get_drvdata(dev);
>         int ctrl2;
> +       int xstp;
>
>         ctrl2 = rx8025_read_reg(client, RX8025_REG_CTRL2);
>         if (ctrl2 < 0)
> @@ -117,7 +142,8 @@ static int rx8025_check_validity(struct device *dev)
>                 return -EINVAL;
>         }
>
> -       if (!(ctrl2 & RX8025_BIT_CTRL2_XST)) {
> +       xstp = rx8025_is_osc_stopped(drvdata->model, ctrl2);
> +       if (xstp) {
>                 dev_warn(dev, "crystal stopped, date is invalid\n");
>                 return -EINVAL;
>         }
> @@ -127,6 +153,7 @@ static int rx8025_check_validity(struct device *dev)
>
>  static int rx8025_reset_validity(struct i2c_client *client)
>  {
> +       struct rx8025_data *drvdata = i2c_get_clientdata(client);
>         int ctrl2 = rx8025_read_reg(client, RX8025_REG_CTRL2);
>
>         if (ctrl2 < 0)
> @@ -134,22 +161,28 @@ static int rx8025_reset_validity(struct i2c_client *client)
>
>         ctrl2 &= ~(RX8025_BIT_CTRL2_PON | RX8025_BIT_CTRL2_VDET);
>
> +       if (drvdata->model == model_rx_8025)
> +               ctrl2 |= RX8025_BIT_CTRL2_XST;
> +       else
> +               ctrl2 &= ~(RX8025_BIT_CTRL2_XST);
> +
>         return rx8025_write_reg(client, RX8025_REG_CTRL2,
> -                               ctrl2 | RX8025_BIT_CTRL2_XST);
> +                               ctrl2);
>  }
>
>  static irqreturn_t rx8025_handle_irq(int irq, void *dev_id)
>  {
>         struct i2c_client *client = dev_id;
>         struct rx8025_data *rx8025 = i2c_get_clientdata(client);
> -       int status;
> +       int status, xstp;
>
>         rtc_lock(rx8025->rtc);
>         status = rx8025_read_reg(client, RX8025_REG_CTRL2);
>         if (status < 0)
>                 goto out;
>
> -       if (!(status & RX8025_BIT_CTRL2_XST))
> +       xstp = rx8025_is_osc_stopped(rx8025->model, status);
> +       if (xstp)
>                 dev_warn(&client->dev, "Oscillation stop was detected,"
>                          "you may have to readjust the clock\n");
>
> @@ -519,6 +552,21 @@ static int rx8025_probe(struct i2c_client *client,
>
>         i2c_set_clientdata(client, rx8025);
>
> +       if (id) {
> +               rx8025->model = id->driver_data;
> +               switch (rx8025->model) {
> +               case model_rx_8025:
> +                       dev_info(&client->dev, "Model RX-8025");
> +                       break;
> +               case model_rx_8035:
> +                       dev_info(&client->dev, "Model RX-8035");
> +                       break;
> +               default:
> +                       dev_warn(&client->dev, "Unknown model: %d\n", rx8025->model);
> +                       break;
> +               }
> +       }
> +
>         err = rx8025_init_client(client);
>         if (err)
>                 return err;
> --
> 2.30.1
>


-- 
Nobuhiro Iwamatsu
   iwamatsu at {nigauri.org / debian.org}
   GPG ID: 40AD1FA6

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/2] dt-bindings: rtc: add Epson RX-8025 and RX-8035
  2021-07-09  4:45 ` [PATCH v2 2/2] dt-bindings: rtc: add Epson RX-8025 and RX-8035 Mathew McBride
  2021-07-14 23:15   ` Rob Herring
@ 2021-07-19  8:18   ` Nobuhiro Iwamatsu
  1 sibling, 0 replies; 7+ messages in thread
From: Nobuhiro Iwamatsu @ 2021-07-19  8:18 UTC (permalink / raw)
  To: Mathew McBride
  Cc: linux-rtc, Alessandro Zummo, Alexandre Belloni, Rob Herring, devicetree

Hi,

2021年7月9日(金) 13:45 Mathew McBride <matt@traverse.com.au>:
>
> These are supported by the rtc-rx8025 module. RX-8025
> also has support in ds1307 due to compatible time registers.
>
> Signed-off-by: Mathew McBride <matt@traverse.com.au>
> ---
>  Documentation/devicetree/bindings/rtc/trivial-rtc.yaml | 3 +++
>  1 file changed, 3 insertions(+)

Reviewed-by: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>

Best regards,
  Nobuhiro

>
> diff --git a/Documentation/devicetree/bindings/rtc/trivial-rtc.yaml b/Documentation/devicetree/bindings/rtc/trivial-rtc.yaml
> index 7548d8714871..13925bb78ec7 100644
> --- a/Documentation/devicetree/bindings/rtc/trivial-rtc.yaml
> +++ b/Documentation/devicetree/bindings/rtc/trivial-rtc.yaml
> @@ -32,6 +32,9 @@ properties:
>        - dallas,ds3232
>        # I2C-BUS INTERFACE REAL TIME CLOCK MODULE
>        - epson,rx8010
> +      # I2C-BUS INTERFACE REAL TIME CLOCK MODULE
> +      - epson,rx8025
> +      - epson,rx8035
>        # I2C-BUS INTERFACE REAL TIME CLOCK MODULE with Battery Backed RAM
>        - epson,rx8571
>        # I2C-BUS INTERFACE REAL TIME CLOCK MODULE
> --
> 2.30.1
>


-- 
Nobuhiro Iwamatsu
   iwamatsu at {nigauri.org / debian.org}
   GPG ID: 40AD1FA6

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 0/2] rtc: Implement support for EPSON RX-8035
  2021-07-09  4:45 [PATCH v2 0/2] rtc: Implement support for EPSON RX-8035 Mathew McBride
  2021-07-09  4:45 ` [PATCH v2 1/2] rtc: rx8025: implement RX-8035 support Mathew McBride
  2021-07-09  4:45 ` [PATCH v2 2/2] dt-bindings: rtc: add Epson RX-8025 and RX-8035 Mathew McBride
@ 2021-08-17 22:08 ` Alexandre Belloni
  2 siblings, 0 replies; 7+ messages in thread
From: Alexandre Belloni @ 2021-08-17 22:08 UTC (permalink / raw)
  To: devicetree, Rob Herring, linux-rtc, Alessandro Zummo, Mathew McBride
  Cc: Alexandre Belloni

On Fri, 9 Jul 2021 04:45:16 +0000, Mathew McBride wrote:
> The EPSON RX-8035[SA] is a I2C real time clock module with
> built-in oscillator[1]. It is a very close relative of the EPSON
> RX-8025 that is supported by the rtc-rx8025 driver.
> 
> The main difference is that the RX-8035 has inverted the
> 'oscillator stop' bit in the control register. The operation
> of the devices is otherwise identical for the features currently
> supported.
> 
> [...]

Applied, thanks!

[1/2] rtc: rx8025: implement RX-8035 support
      commit: f120e2e33ac8ba1adac4f59eaf1ae1705305158f

I did remove the switch and dev_info in an attempt to cut down on unecessary
strings.

[2/2] dt-bindings: rtc: add Epson RX-8025 and RX-8035
      commit: 8158da6a33f2656c2a98c30eb9185a44e215a6b6

Best regards,
-- 
Alexandre Belloni <alexandre.belloni@bootlin.com>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-08-17 22:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-09  4:45 [PATCH v2 0/2] rtc: Implement support for EPSON RX-8035 Mathew McBride
2021-07-09  4:45 ` [PATCH v2 1/2] rtc: rx8025: implement RX-8035 support Mathew McBride
2021-07-19  8:15   ` Nobuhiro Iwamatsu
2021-07-09  4:45 ` [PATCH v2 2/2] dt-bindings: rtc: add Epson RX-8025 and RX-8035 Mathew McBride
2021-07-14 23:15   ` Rob Herring
2021-07-19  8:18   ` Nobuhiro Iwamatsu
2021-08-17 22:08 ` [PATCH v2 0/2] rtc: Implement support for EPSON RX-8035 Alexandre Belloni

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.