All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/5] Add Renesas PMIC RAA215300 and built-in RTC support
@ 2023-05-05 17:25 Biju Das
  2023-05-05 17:25 ` [PATCH v2 1/5] dt-bindings: mfd: Add Renesas RAA215300 PMIC bindings Biju Das
                   ` (4 more replies)
  0 siblings, 5 replies; 18+ messages in thread
From: Biju Das @ 2023-05-05 17:25 UTC (permalink / raw)
  To: Lee Jones, Alessandro Zummo, Alexandre Belloni, Rob Herring,
	Krzysztof Kozlowski
  Cc: Biju Das, Geert Uytterhoeven, Magnus Damm, devicetree, linux-rtc,
	linux-renesas-soc, Fabrizio Castro

This patch series aims to add support for Renesas PMIC RAA215300 and
built-in RTC found on this PMIC device.

The details of PMIC can be found here[1].

The built-in RTC is same as ISL-1208. Enabling of the
RTC is done by the PMIC module. Also the external osciallator bit is
inverted on PMIC version 0x12 and later. The PMIC version is shared
between PMIC driver and RTC driver.

RAA215300PMIC driver has MFD cell entry for RTC platform driver and it
instantiates the RTC platform driver. RTC platform creates rtc device by
using i2c_new_ancillary_device() and register the rtc device by
calling the helper function provided by rtc-isl2108 driver.

[1]
https://www.renesas.com/in/en/products/power-power-management/multi-channel-power-management-ics-pmics/ssdsoc-power-management-ics-pmic-and-pmus/raa215300-high-performance-9-channel-pmic-supporting-ddr-memory-built-charger-and-rtc

[2]
 https://patchwork.kernel.org/project/linux-renesas-soc/patch/20230505091720.115675-1-biju.das.jz@bp.renesas.com/

RFC->v2:
 * Dropped the cross-links from bindings and used a single compatible
   with separate i2c addresses for pmic main and rtc device.
 * Dropped patch#4 and split patch#3 from this series and send as
   separate patch to ML [2].
 * Added RTC platform driver and mfd cell entry to the PMIC driver.RTC
   platform driver creates rtc device by using i2c_new_ancillary_device()
   and register the rtc device by calling the helper function provided
   by rtc-isl2108 driver.
 * Updated reg property in bindings.
 * Added optional reg-names, interrupts and renesas,rtc-enabled
   properties.
 * Fixed the node name in the binding example
 * Dropped the cross link property renesas,raa215300-rtc.
 * Updated the binding example
 * Dropped MODULE_SOFTDEP from the driver as it is added in RTC platform
   driver.
 * Dropped compatible "renesas,raa215300-isl1208" and "renesas,raa215300-pmic" property.
 * Updated the comment polarity->bit for External Oscillator.
 * Added raa215300_rtc_probe_helper() for registering raa215300_rtc device and
   added the helper function isl1208_probe_helper() to share the code.
 * Updated pmic device node on the SoM dtsi based on the bindings.

Logs:
[   15.055110] dummy 3-006f: registered as rtc0
[   15.189869] dummy 3-006f: setting system clock to 2023-04-27T19:32:41 UTC (1682623961)

root@smarc-rzg2l:~# hwclock -r
2023-04-27 19:43:09.802884+00:00
root@smarc-rzg2l:~# hwclock -r
2023-04-27 19:43:10.996184+00:00
root@smarc-rzg2l:~#

Biju Das (5):
  dt-bindings: mfd: Add Renesas RAA215300 PMIC bindings
  mfd: Add Renesas PMIC RAA215300 driver
  rtc: isl1208: Add support for the built-in RTC on the PMIC RAA215300
  mfd: Add Renesas PMIC RAA215300 RTC driver
  arm64: dts: renesas: rzg2l-smarc-som: Enable PMIC and built-in RTC

 .../bindings/mfd/renesas,raa215300.yaml       |  68 +++++++++++
 .../boot/dts/renesas/rzg2l-smarc-som.dtsi     |  10 ++
 drivers/mfd/Kconfig                           |  14 +++
 drivers/mfd/Makefile                          |   3 +
 drivers/mfd/raa215300-rtc.c                   |  52 +++++++++
 drivers/mfd/raa215300.c                       | 106 ++++++++++++++++++
 drivers/rtc/rtc-isl1208.c                     |  61 ++++++++--
 include/linux/rtc/isl1208.h                   |   9 ++
 8 files changed, 312 insertions(+), 11 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mfd/renesas,raa215300.yaml
 create mode 100644 drivers/mfd/raa215300-rtc.c
 create mode 100644 drivers/mfd/raa215300.c
 create mode 100644 include/linux/rtc/isl1208.h

-- 
2.25.1


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

* [PATCH v2 1/5] dt-bindings: mfd: Add Renesas RAA215300 PMIC bindings
  2023-05-05 17:25 [PATCH v2 0/5] Add Renesas PMIC RAA215300 and built-in RTC support Biju Das
@ 2023-05-05 17:25 ` Biju Das
  2023-05-05 18:08   ` Krzysztof Kozlowski
  2023-05-05 17:25 ` [PATCH v2 2/5] mfd: Add Renesas PMIC RAA215300 driver Biju Das
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 18+ messages in thread
From: Biju Das @ 2023-05-05 17:25 UTC (permalink / raw)
  To: Lee Jones, Rob Herring, Krzysztof Kozlowski
  Cc: Biju Das, Geert Uytterhoeven, Magnus Damm, devicetree,
	linux-renesas-soc, Fabrizio Castro

Document Renesas RAA215300 PMIC bindings.

The RAA215300 is a high Performance 9-Channel PMIC supporting DDR
Memory, with Built-In Charger and RTC.

It supports DDR3, DDR3L, DDR4, and LPDDR4 memory power requirements.
The internally compensated regulators, built-in Real-Time Clock (RTC),
32kHz crystal oscillator, and coin cell battery charger provide a
highly integrated, small footprint power solution ideal for
System-On-Module (SOM) applications. A spread spectrum feature
provides an ease-of-use solution for noise-sensitive audio or RF
applications.

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
RFC->v2:
 * Updated reg property
 * Added optional reg-names, interrupts and renesas,rtc-enabled
   properties.
 * Fixed the node name in the example
 * Dropped the cross link property renesas,raa215300-rtc.
 * Updated the example
---
 .../bindings/mfd/renesas,raa215300.yaml       | 68 +++++++++++++++++++
 1 file changed, 68 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/renesas,raa215300.yaml

diff --git a/Documentation/devicetree/bindings/mfd/renesas,raa215300.yaml b/Documentation/devicetree/bindings/mfd/renesas,raa215300.yaml
new file mode 100644
index 000000000000..85cb4f0b5711
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/renesas,raa215300.yaml
@@ -0,0 +1,68 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/renesas,raa215300.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Renesas RAA215300 Power Management Integrated Circuit (PMIC)
+
+maintainers:
+  - Biju Das <biju.das.jz@bp.renesas.com>
+
+description: |
+  The RAA215300 is a high-performance, low-cost 9-channel PMIC designed for
+  32-bit and 64-bit MCU and MPU applications. It supports DDR3, DDR3L, DDR4,
+  and LPDDR4 memory power requirements. The internally compensated regulators,
+  built-in Real-Time Clock (RTC), 32kHz crystal oscillator, and coin cell
+  battery charger provide a highly integrated, small footprint power solution
+  ideal for System-On-Module (SOM) applications. A spread spectrum feature
+  provides an ease-of-use solution for noise-sensitive audio or RF applications.
+
+  This device exposes two devices via I2C. One for the integrated RTC IP, and
+  one for everything else.
+
+  Link to datasheet:
+  https://www.renesas.com/in/en/products/power-power-management/multi-channel-power-management-ics-pmics/ssdsoc-power-management-ics-pmic-and-pmus/raa215300-high-performance-9-channel-pmic-supporting-ddr-memory-built-charger-and-rtc
+
+properties:
+  compatible:
+    enum:
+      - renesas,raa215300
+
+  reg:
+    minItems: 1
+    maxItems: 2
+
+  reg-names:
+    items:
+      - const: main
+      - const: rtc
+
+  interrupts:
+    maxItems: 1
+
+  renesas,rtc-enabled:
+    description:
+      To indicate RTC is enabled on the PMIC.
+    type: boolean
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        raa215300: pmic@12 {
+            compatible = "renesas,raa215300";
+            reg = <0x12>, <0x6f>;
+            reg-names = "main", "rtc";
+
+            renesas,rtc-enabled;
+        };
+    };
-- 
2.25.1


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

* [PATCH v2 2/5] mfd: Add Renesas PMIC RAA215300 driver
  2023-05-05 17:25 [PATCH v2 0/5] Add Renesas PMIC RAA215300 and built-in RTC support Biju Das
  2023-05-05 17:25 ` [PATCH v2 1/5] dt-bindings: mfd: Add Renesas RAA215300 PMIC bindings Biju Das
@ 2023-05-05 17:25 ` Biju Das
  2023-05-05 17:25 ` [PATCH v2 3/5] rtc: isl1208: Add support for the built-in RTC on the PMIC RAA215300 Biju Das
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 18+ messages in thread
From: Biju Das @ 2023-05-05 17:25 UTC (permalink / raw)
  To: Lee Jones
  Cc: Biju Das, Geert Uytterhoeven, Alessandro Zummo,
	Alexandre Belloni, Magnus Damm, linux-renesas-soc,
	Fabrizio Castro

The RAA215300 is a 9-channel PMIC that consists of
 * Internally compensated regulators
 * built-in Real Time Clock (RTC)
 * 32kHz crystal oscillator
 * coin cell battery charger

The RTC on RAA215300 is similar to the IP found in the ISL1208.
The existing driver for the ISL1208 works for this PMIC too,
however the RAA215300 exposes two devices via I2C, one for the RTC
IP, and one for everything else. The RTC IP has to be enabled
by the other I2C device, therefore this driver is necessary to get
the RTC to work.

Add support for basic PMIC RAA215300 driver. Support for enabling RTC
and sharing PMIC version to the RTC driver done in the subsequent
patch.

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
RFC->V2:
 * Dropped MODULE_SOFTDEP from the driver as it is added in RTC platform
   driver.
---
 drivers/mfd/Kconfig     |  7 ++++
 drivers/mfd/Makefile    |  2 ++
 drivers/mfd/raa215300.c | 74 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 83 insertions(+)
 create mode 100644 drivers/mfd/raa215300.c

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index e90463c4441c..9071b0f27b62 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -311,6 +311,13 @@ config MFD_CS47L92
 	help
 	  Support for Cirrus Logic CS42L92, CS47L92 and CS47L93 Smart Codecs
 
+config PMIC_RAA215300
+	tristate "Renesas RAA215300 driver"
+	select REGMAP_I2C
+	depends on I2C
+	help
+	  Support for the Renesas RAA215300 PMIC.
+
 config PMIC_DA903X
 	bool "Dialog Semiconductor DA9030/DA9034 PMIC Support"
 	depends on I2C=y
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 1d2392f06f78..d9c601120bfd 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -126,6 +126,8 @@ ifeq ($(CONFIG_SA1100_ASSABET),y)
 obj-$(CONFIG_MCP_UCB1200)	+= ucb1x00-assabet.o
 endif
 
+obj-$(CONFIG_PMIC_RAA215300)	+= raa215300.o
+
 obj-$(CONFIG_PMIC_DA903X)	+= da903x.o
 
 obj-$(CONFIG_PMIC_DA9052)	+= da9052-irq.o
diff --git a/drivers/mfd/raa215300.c b/drivers/mfd/raa215300.c
new file mode 100644
index 000000000000..5cdd3213e99c
--- /dev/null
+++ b/drivers/mfd/raa215300.c
@@ -0,0 +1,74 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Renesas RAA215300 PMIC driver
+ *
+ * Copyright (C) 2023 Renesas Electronics Corporation
+ */
+
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/regmap.h>
+
+#define RAA215300_REG_BLOCK_EN	0x6c
+#define RAA215300_HW_REV	0xf8
+
+#define RAA215300_REG_BLOCK_EN_RTC_EN	BIT(6)
+
+static bool raa215300_is_volatile_reg(struct device *dev, unsigned int reg)
+{
+	return true;
+}
+
+static const struct regmap_config raa215300_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.max_register = 0xff,
+	.volatile_reg = raa215300_is_volatile_reg,
+	.cache_type = REGCACHE_FLAT,
+};
+
+static int raa215300_i2c_probe(struct i2c_client *client)
+{
+	struct device *dev = &client->dev;
+	unsigned int pmic_version;
+	struct regmap *regmap;
+	int ret;
+
+	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
+		return -EOPNOTSUPP;
+
+	regmap = devm_regmap_init_i2c(client, &raa215300_regmap_config);
+	if (IS_ERR(regmap))
+		return dev_err_probe(dev, PTR_ERR(regmap),
+				     "regmap i2c init failed\n");
+
+	ret = regmap_read(regmap, RAA215300_HW_REV, &pmic_version);
+	if (ret < 0)
+		return dev_err_probe(dev, ret, "HW rev read failed\n");
+
+	dev_dbg(dev, "RAA215300 PMIC version 0x%04x\n", pmic_version);
+
+	return 0;
+}
+
+static const struct of_device_id raa215300_dt_match[] = {
+	{ .compatible = "renesas,raa215300" },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, raa215300_dt_match);
+
+static struct i2c_driver raa215300_i2c_driver = {
+	.driver = {
+		.name = "raa215300",
+		.of_match_table = raa215300_dt_match,
+	},
+	.probe_new = raa215300_i2c_probe,
+};
+module_i2c_driver(raa215300_i2c_driver);
+
+MODULE_DESCRIPTION("Renesas RAA215300 PMIC driver");
+MODULE_AUTHOR("Fabrizio Castro <fabrizio.castro.jz@renesas.com>");
+MODULE_AUTHOR("Biju Das <biju.das.jz@bp.renesas.com>");
+MODULE_LICENSE("GPL");
-- 
2.25.1


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

* [PATCH v2 3/5] rtc: isl1208: Add support for the built-in RTC on the PMIC RAA215300
  2023-05-05 17:25 [PATCH v2 0/5] Add Renesas PMIC RAA215300 and built-in RTC support Biju Das
  2023-05-05 17:25 ` [PATCH v2 1/5] dt-bindings: mfd: Add Renesas RAA215300 PMIC bindings Biju Das
  2023-05-05 17:25 ` [PATCH v2 2/5] mfd: Add Renesas PMIC RAA215300 driver Biju Das
@ 2023-05-05 17:25 ` Biju Das
  2023-05-05 17:25 ` [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300 RTC driver Biju Das
  2023-05-05 17:25 ` [PATCH v2 5/5] arm64: dts: renesas: rzg2l-smarc-som: Enable PMIC and built-in RTC Biju Das
  4 siblings, 0 replies; 18+ messages in thread
From: Biju Das @ 2023-05-05 17:25 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni
  Cc: Biju Das, Geert Uytterhoeven, Magnus Damm, Lee Jones, linux-rtc,
	linux-renesas-soc, Fabrizio Castro

The built-in RTC found on PMIC RAA215300 is the same as ISL1208.
However, the external oscillator bit is inverted on PMIC version
0x12 and later. This info needs to be shared from the PMIC driver
to the RTC driver so that it can support all versions without any
code changes.

Add support for RTC found on PMIC RAA215300 by adding a helper
function for registering the RTC device.

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
RFC->v2:
 * Dropped compatible "renesas,raa215300-isl1208" and "renesas,raa215300-pmic" property.
 * Updated the comment polarity->bit for External Oscillator.
 * Added raa215300_rtc_probe_helper() for registering raa215300_rtc device and
   added the helper function isl1208_probe_helper() to share the code.
---
 drivers/rtc/rtc-isl1208.c   | 61 ++++++++++++++++++++++++++++++-------
 include/linux/rtc/isl1208.h |  9 ++++++
 2 files changed, 59 insertions(+), 11 deletions(-)
 create mode 100644 include/linux/rtc/isl1208.h

diff --git a/drivers/rtc/rtc-isl1208.c b/drivers/rtc/rtc-isl1208.c
index 73cc6aaf9b8b..f2dc96d3e4e1 100644
--- a/drivers/rtc/rtc-isl1208.c
+++ b/drivers/rtc/rtc-isl1208.c
@@ -166,6 +166,19 @@ isl1208_i2c_validate_client(struct i2c_client *client)
 	return 0;
 }
 
+static int
+isl1208_set_ext_osc_based_on_pmic_version(struct i2c_client *client, int rc,
+					  unsigned int pmic_version)
+{
+	/* External Oscillator bit is inverted on revision 0x12 and later */
+	if (pmic_version >= 0x12)
+		rc &= ~ISL1208_REG_SR_XTOSCB;
+	else
+		rc |= ISL1208_REG_SR_XTOSCB;
+
+	return i2c_smbus_write_byte_data(client, ISL1208_REG_SR, rc);
+}
+
 static int
 isl1208_i2c_get_sr(struct i2c_client *client)
 {
@@ -797,7 +810,8 @@ static int isl1208_setup_irq(struct i2c_client *client, int irq)
 }
 
 static int
-isl1208_probe(struct i2c_client *client)
+isl1208_probe_helper(struct i2c_client *client, bool is_raa215300_rtc,
+		     unsigned int pmic_version)
 {
 	int rc = 0;
 	struct isl1208_state *isl1208;
@@ -815,17 +829,22 @@ isl1208_probe(struct i2c_client *client)
 		return -ENOMEM;
 	i2c_set_clientdata(client, isl1208);
 
-	/* Determine which chip we have */
-	if (client->dev.of_node) {
-		isl1208->config = of_device_get_match_data(&client->dev);
-		if (!isl1208->config)
-			return -ENODEV;
+	if (is_raa215300_rtc) {
+		isl1208->config = &isl1208_configs[TYPE_ISL1208];
 	} else {
-		const struct i2c_device_id *id = i2c_match_id(isl1208_id, client);
-
-		if (id->driver_data >= ISL_LAST_ID)
-			return -ENODEV;
-		isl1208->config = &isl1208_configs[id->driver_data];
+		/* Determine which chip we have */
+		if (client->dev.of_node) {
+			isl1208->config = of_device_get_match_data(&client->dev);
+			if (!isl1208->config)
+				return -ENODEV;
+		} else {
+			const struct i2c_device_id *id = i2c_match_id(isl1208_id,
+								      client);
+
+			if (id->driver_data >= ISL_LAST_ID)
+				return -ENODEV;
+			isl1208->config = &isl1208_configs[id->driver_data];
+		}
 	}
 
 	isl1208->rtc = devm_rtc_allocate_device(&client->dev);
@@ -845,6 +864,13 @@ isl1208_probe(struct i2c_client *client)
 		return rc;
 	}
 
+	if (is_raa215300_rtc) {
+		rc = isl1208_set_ext_osc_based_on_pmic_version(client, rc,
+							       pmic_version);
+		if (rc)
+			return rc;
+	}
+
 	if (rc & ISL1208_REG_SR_RTCF)
 		dev_warn(&client->dev, "rtc power failure detected, "
 			 "please set clock.\n");
@@ -903,6 +929,19 @@ isl1208_probe(struct i2c_client *client)
 	return devm_rtc_register_device(isl1208->rtc);
 }
 
+static int
+isl1208_probe(struct i2c_client *client)
+{
+	return isl1208_probe_helper(client, false, 0);
+}
+
+int
+raa215300_rtc_probe_helper(struct i2c_client *client, unsigned int pmic_version)
+{
+	return isl1208_probe_helper(client, true, pmic_version);
+}
+EXPORT_SYMBOL(raa215300_rtc_probe_helper);
+
 static struct i2c_driver isl1208_driver = {
 	.driver = {
 		.name = "rtc-isl1208",
diff --git a/include/linux/rtc/isl1208.h b/include/linux/rtc/isl1208.h
new file mode 100644
index 000000000000..1dee540f9ab4
--- /dev/null
+++ b/include/linux/rtc/isl1208.h
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef _LINUX_ISL1208_H_
+#define _LINUX_ISL1208_H_
+
+int raa215300_rtc_probe_helper(struct i2c_client *client,
+			       unsigned int pmic_version);
+
+#endif /* _LINUX_ISL1208_H_ */
-- 
2.25.1


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

* [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300 RTC driver
  2023-05-05 17:25 [PATCH v2 0/5] Add Renesas PMIC RAA215300 and built-in RTC support Biju Das
                   ` (2 preceding siblings ...)
  2023-05-05 17:25 ` [PATCH v2 3/5] rtc: isl1208: Add support for the built-in RTC on the PMIC RAA215300 Biju Das
@ 2023-05-05 17:25 ` Biju Das
  2023-05-09  7:06   ` Biju Das
  2023-05-05 17:25 ` [PATCH v2 5/5] arm64: dts: renesas: rzg2l-smarc-som: Enable PMIC and built-in RTC Biju Das
  4 siblings, 1 reply; 18+ messages in thread
From: Biju Das @ 2023-05-05 17:25 UTC (permalink / raw)
  To: Lee Jones
  Cc: Biju Das, Geert Uytterhoeven, Alessandro Zummo,
	Alexandre Belloni, Magnus Damm, linux-renesas-soc,
	Fabrizio Castro

Currently, it is not possible to instantiate the i2c client driver using
MFD cell as it is not a platform driver. Add support for Renesas PMIC
RAA215300 RTC platform driver, so that it can be instantiated by MFD API.
The rtc device is created by using i2c_new_ancillary_device() and 
it register as the rtc device by the helper function provided by
rtc-isl2108 driver.

The PMIC driver enables RTC device and share the PMIC revision to
RTC platform driver.

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
v2:
 * New patch
---
 drivers/mfd/Kconfig         |  7 +++++
 drivers/mfd/Makefile        |  1 +
 drivers/mfd/raa215300-rtc.c | 52 +++++++++++++++++++++++++++++++++++++
 drivers/mfd/raa215300.c     | 38 ++++++++++++++++++++++++---
 4 files changed, 95 insertions(+), 3 deletions(-)
 create mode 100644 drivers/mfd/raa215300-rtc.c

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 9071b0f27b62..cec20c1f143d 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -318,6 +318,13 @@ config PMIC_RAA215300
 	help
 	  Support for the Renesas RAA215300 PMIC.
 
+config PMIC_RAA215300_RTC
+	tristate "Renesas RAA215300 RTC driver"
+	depends on PMIC_RAA215300
+	select RTC_DRV_ISL1208
+	help
+	  Select this to get support for the Renesas RAA215300 RTC
+
 config PMIC_DA903X
 	bool "Dialog Semiconductor DA9030/DA9034 PMIC Support"
 	depends on I2C=y
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index d9c601120bfd..ed4b760e564e 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -127,6 +127,7 @@ obj-$(CONFIG_MCP_UCB1200)	+= ucb1x00-assabet.o
 endif
 
 obj-$(CONFIG_PMIC_RAA215300)	+= raa215300.o
+obj-$(CONFIG_PMIC_RAA215300_RTC)	+= raa215300-rtc.o
 
 obj-$(CONFIG_PMIC_DA903X)	+= da903x.o
 
diff --git a/drivers/mfd/raa215300-rtc.c b/drivers/mfd/raa215300-rtc.c
new file mode 100644
index 000000000000..309ed34d6cd7
--- /dev/null
+++ b/drivers/mfd/raa215300-rtc.c
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Renesas RAA215300 RTC Driver
+ *
+ * Copyright (C) 2023 Renesas Electronics Corporation
+ */
+
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/rtc/isl1208.h>
+
+#define RAA215300_RTC_DEFAULT_ADDR 0x6f
+
+static void raa215300_rtc_unregister_device(void *data)
+{
+	i2c_unregister_device(data);
+}
+
+static int raa215300_rtc_probe(struct platform_device *pdev)
+{
+	unsigned int *pmic_version = dev_get_drvdata(pdev->dev.parent);
+	struct i2c_client *client;
+	int ret;
+
+	client = i2c_new_ancillary_device(to_i2c_client(pdev->dev.parent),
+					  "rtc", RAA215300_RTC_DEFAULT_ADDR);
+	if (IS_ERR(client))
+		return PTR_ERR(client);
+
+	ret = devm_add_action_or_reset(&pdev->dev,
+				       raa215300_rtc_unregister_device, client);
+	if (ret < 0)
+		return ret;
+
+	return raa215300_rtc_probe_helper(client, *pmic_version);
+}
+
+static struct platform_driver raa215300_rtc_driver = {
+	.probe = raa215300_rtc_probe,
+	.driver = {
+		.name = "raa215300-rtc",
+	},
+};
+module_platform_driver(raa215300_rtc_driver);
+
+MODULE_DESCRIPTION("Renesas RAA215300 MFD RTC Driver");
+MODULE_ALIAS("platform:raa215300-rtc");
+MODULE_AUTHOR("Biju Das <biju.das.jz@bp.renesas.com>");
+MODULE_LICENSE("GPL");
+MODULE_SOFTDEP("post: rtc_isl1208");
diff --git a/drivers/mfd/raa215300.c b/drivers/mfd/raa215300.c
index 5cdd3213e99c..c8bdf96b203f 100644
--- a/drivers/mfd/raa215300.c
+++ b/drivers/mfd/raa215300.c
@@ -8,6 +8,7 @@
 #include <linux/err.h>
 #include <linux/i2c.h>
 #include <linux/module.h>
+#include <linux/mfd/core.h>
 #include <linux/of.h>
 #include <linux/regmap.h>
 
@@ -29,13 +30,26 @@ static const struct regmap_config raa215300_regmap_config = {
 	.cache_type = REGCACHE_FLAT,
 };
 
+static const struct mfd_cell raa215300_rtc_dev[] = {
+	{ .name = "raa215300-rtc" }
+};
+
+static void raa215300_remove_devices(void *data)
+{
+	mfd_remove_devices(data);
+}
+
 static int raa215300_i2c_probe(struct i2c_client *client)
 {
 	struct device *dev = &client->dev;
-	unsigned int pmic_version;
+	unsigned int *pmic_version;
 	struct regmap *regmap;
 	int ret;
 
+	pmic_version = devm_kzalloc(dev, sizeof(*pmic_version), GFP_KERNEL);
+	if (!pmic_version)
+		return -ENOMEM;
+
 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
 		return -EOPNOTSUPP;
 
@@ -44,11 +58,29 @@ static int raa215300_i2c_probe(struct i2c_client *client)
 		return dev_err_probe(dev, PTR_ERR(regmap),
 				     "regmap i2c init failed\n");
 
-	ret = regmap_read(regmap, RAA215300_HW_REV, &pmic_version);
+	ret = regmap_read(regmap, RAA215300_HW_REV, pmic_version);
 	if (ret < 0)
 		return dev_err_probe(dev, ret, "HW rev read failed\n");
 
-	dev_dbg(dev, "RAA215300 PMIC version 0x%04x\n", pmic_version);
+	dev_dbg(dev, "RAA215300 PMIC version 0x%04x\n", *pmic_version);
+	dev_set_drvdata(dev, pmic_version);
+
+	if (of_property_read_bool(dev->of_node, "renesas,rtc-enabled"))  {
+		/* Enable RTC block */
+		regmap_update_bits(regmap, RAA215300_REG_BLOCK_EN,
+				   RAA215300_REG_BLOCK_EN_RTC_EN,
+				   RAA215300_REG_BLOCK_EN_RTC_EN);
+
+		ret = mfd_add_devices(dev, 0, raa215300_rtc_dev,
+				      ARRAY_SIZE(raa215300_rtc_dev), NULL,
+				      0, NULL);
+		if (ret < 0)
+			return ret;
+
+		ret = devm_add_action_or_reset(dev, raa215300_remove_devices, dev);
+		if (ret < 0)
+			return ret;
+	}
 
 	return 0;
 }
-- 
2.25.1


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

* [PATCH v2 5/5] arm64: dts: renesas: rzg2l-smarc-som: Enable PMIC and built-in RTC
  2023-05-05 17:25 [PATCH v2 0/5] Add Renesas PMIC RAA215300 and built-in RTC support Biju Das
                   ` (3 preceding siblings ...)
  2023-05-05 17:25 ` [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300 RTC driver Biju Das
@ 2023-05-05 17:25 ` Biju Das
  4 siblings, 0 replies; 18+ messages in thread
From: Biju Das @ 2023-05-05 17:25 UTC (permalink / raw)
  To: Rob Herring, Krzysztof Kozlowski
  Cc: Biju Das, Geert Uytterhoeven, Magnus Damm, linux-renesas-soc,
	devicetree, Fabrizio Castro

Enable PMIC RAA215300 and the built-in RTC on the RZ/{G2L,V2L} SMARC
EVK.

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
RFC->V2:
 * Updated pmic device node based on the bindings.
---
 arch/arm64/boot/dts/renesas/rzg2l-smarc-som.dtsi | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/arch/arm64/boot/dts/renesas/rzg2l-smarc-som.dtsi b/arch/arm64/boot/dts/renesas/rzg2l-smarc-som.dtsi
index fbbb4f03440b..ffe19d2f0e37 100644
--- a/arch/arm64/boot/dts/renesas/rzg2l-smarc-som.dtsi
+++ b/arch/arm64/boot/dts/renesas/rzg2l-smarc-som.dtsi
@@ -351,3 +351,13 @@ &wdt1 {
 	status = "okay";
 	timeout-sec = <60>;
 };
+
+&i2c3 {
+	raa215300: pmic@12 {
+		compatible = "renesas,raa215300";
+		reg = <0x12>, <0x6f>;
+		reg-names = "main", "rtc";
+
+		renesas,rtc-enabled;
+	};
+};
-- 
2.25.1


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

* Re: [PATCH v2 1/5] dt-bindings: mfd: Add Renesas RAA215300 PMIC bindings
  2023-05-05 17:25 ` [PATCH v2 1/5] dt-bindings: mfd: Add Renesas RAA215300 PMIC bindings Biju Das
@ 2023-05-05 18:08   ` Krzysztof Kozlowski
  2023-05-05 18:21     ` Biju Das
  0 siblings, 1 reply; 18+ messages in thread
From: Krzysztof Kozlowski @ 2023-05-05 18:08 UTC (permalink / raw)
  To: Biju Das, Lee Jones, Rob Herring, Krzysztof Kozlowski
  Cc: Geert Uytterhoeven, Magnus Damm, devicetree, linux-renesas-soc,
	Fabrizio Castro

On 05/05/2023 19:25, Biju Das wrote:
> Document Renesas RAA215300 PMIC bindings.
> 
> The RAA215300 is a high Performance 9-Channel PMIC supporting DDR
> Memory, with Built-In Charger and RTC.
> 
> It supports DDR3, DDR3L, DDR4, and LPDDR4 memory power requirements.
> The internally compensated regulators, built-in Real-Time Clock (RTC),
> 32kHz crystal oscillator, and coin cell battery charger provide a
> highly integrated, small footprint power solution ideal for
> System-On-Module (SOM) applications. A spread spectrum feature
> provides an ease-of-use solution for noise-sensitive audio or RF
> applications.
> 
> Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
> ---
> RFC->v2:
>  * Updated reg property
>  * Added optional reg-names, interrupts and renesas,rtc-enabled
>    properties.
>  * Fixed the node name in the example
>  * Dropped the cross link property renesas,raa215300-rtc.
>  * Updated the example
> ---
>  .../bindings/mfd/renesas,raa215300.yaml       | 68 +++++++++++++++++++
>  1 file changed, 68 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/mfd/renesas,raa215300.yaml
> 
> diff --git a/Documentation/devicetree/bindings/mfd/renesas,raa215300.yaml b/Documentation/devicetree/bindings/mfd/renesas,raa215300.yaml
> new file mode 100644
> index 000000000000..85cb4f0b5711
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/mfd/renesas,raa215300.yaml
> @@ -0,0 +1,68 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/mfd/renesas,raa215300.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Renesas RAA215300 Power Management Integrated Circuit (PMIC)
> +
> +maintainers:
> +  - Biju Das <biju.das.jz@bp.renesas.com>
> +
> +description: |
> +  The RAA215300 is a high-performance, low-cost 9-channel PMIC designed for
> +  32-bit and 64-bit MCU and MPU applications. It supports DDR3, DDR3L, DDR4,
> +  and LPDDR4 memory power requirements. The internally compensated regulators,
> +  built-in Real-Time Clock (RTC), 32kHz crystal oscillator, and coin cell
> +  battery charger provide a highly integrated, small footprint power solution
> +  ideal for System-On-Module (SOM) applications. A spread spectrum feature
> +  provides an ease-of-use solution for noise-sensitive audio or RF applications.
> +
> +  This device exposes two devices via I2C. One for the integrated RTC IP, and
> +  one for everything else.
> +
> +  Link to datasheet:
> +  https://www.renesas.com/in/en/products/power-power-management/multi-channel-power-management-ics-pmics/ssdsoc-power-management-ics-pmic-and-pmus/raa215300-high-performance-9-channel-pmic-supporting-ddr-memory-built-charger-and-rtc
> +
> +properties:
> +  compatible:
> +    enum:
> +      - renesas,raa215300
> +
> +  reg:
> +    minItems: 1
> +    maxItems: 2
> +
> +  reg-names:
> +    items:
> +      - const: main
> +      - const: rtc
> +
> +  interrupts:
> +    maxItems: 1
> +
> +  renesas,rtc-enabled:
> +    description:
> +      To indicate RTC is enabled on the PMIC.

"Enabled" by who or what? This looks like some policy, so Devicetree is
not a place for it.

> +    type: boolean
> +
> +required:
> +  - compatible
> +  - reg


Best regards,
Krzysztof


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

* RE: [PATCH v2 1/5] dt-bindings: mfd: Add Renesas RAA215300 PMIC bindings
  2023-05-05 18:08   ` Krzysztof Kozlowski
@ 2023-05-05 18:21     ` Biju Das
  2023-05-05 18:32       ` Krzysztof Kozlowski
  0 siblings, 1 reply; 18+ messages in thread
From: Biju Das @ 2023-05-05 18:21 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Lee Jones, Rob Herring, Krzysztof Kozlowski
  Cc: Geert Uytterhoeven, Magnus Damm, devicetree, linux-renesas-soc,
	Fabrizio Castro

Hi Krzysztof Kozlowski,

Thanks for the feedback.

> Subject: Re: [PATCH v2 1/5] dt-bindings: mfd: Add Renesas RAA215300 PMIC
> bindings
> 
> On 05/05/2023 19:25, Biju Das wrote:
> > Document Renesas RAA215300 PMIC bindings.
> >
> > The RAA215300 is a high Performance 9-Channel PMIC supporting DDR
> > Memory, with Built-In Charger and RTC.
> >
> > It supports DDR3, DDR3L, DDR4, and LPDDR4 memory power requirements.
> > The internally compensated regulators, built-in Real-Time Clock (RTC),
> > 32kHz crystal oscillator, and coin cell battery charger provide a
> > highly integrated, small footprint power solution ideal for
> > System-On-Module (SOM) applications. A spread spectrum feature
> > provides an ease-of-use solution for noise-sensitive audio or RF
> > applications.
> >
> > Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
> > ---
> > RFC->v2:
> >  * Updated reg property
> >  * Added optional reg-names, interrupts and renesas,rtc-enabled
> >    properties.
> >  * Fixed the node name in the example
> >  * Dropped the cross link property renesas,raa215300-rtc.
> >  * Updated the example
> > ---
> >  .../bindings/mfd/renesas,raa215300.yaml       | 68 +++++++++++++++++++
> >  1 file changed, 68 insertions(+)
> >  create mode 100644
> > Documentation/devicetree/bindings/mfd/renesas,raa215300.yaml
> >
> > diff --git
> > a/Documentation/devicetree/bindings/mfd/renesas,raa215300.yaml
> > b/Documentation/devicetree/bindings/mfd/renesas,raa215300.yaml
> > new file mode 100644
> > index 000000000000..85cb4f0b5711
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/mfd/renesas,raa215300.yaml
> > @@ -0,0 +1,68 @@
> > +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) %YAML 1.2
> > +---
> > +$id:
> > +
> > +title: Renesas RAA215300 Power Management Integrated Circuit (PMIC)
> > +
> > +maintainers:
> > +  - Biju Das <biju.das.jz@bp.renesas.com>
> > +
> > +description: |
> > +  The RAA215300 is a high-performance, low-cost 9-channel PMIC
> > +designed for
> > +  32-bit and 64-bit MCU and MPU applications. It supports DDR3,
> > +DDR3L, DDR4,
> > +  and LPDDR4 memory power requirements. The internally compensated
> > +regulators,
> > +  built-in Real-Time Clock (RTC), 32kHz crystal oscillator, and coin
> > +cell
> > +  battery charger provide a highly integrated, small footprint power
> > +solution
> > +  ideal for System-On-Module (SOM) applications. A spread spectrum
> > +feature
> > +  provides an ease-of-use solution for noise-sensitive audio or RF
> applications.
> > +
> > +  This device exposes two devices via I2C. One for the integrated RTC
> > + IP, and  one for everything else.
> > +
> > +  Link to datasheet:
> > +
> > + https://www.renesas.com/in/en/products/power-power-management/multi-
> > + channel-power-management-ics-pmics/ssdsoc-power-management-ics-pmic-
> > + and-pmus/raa215300-high-performance-9-channel-pmic-supporting-ddr-me
> > + mory-built-charger-and-rtc
> > +
> > +properties:
> > +  compatible:
> > +    enum:
> > +      - renesas,raa215300
> > +
> > +  reg:
> > +    minItems: 1
> > +    maxItems: 2
> > +
> > +  reg-names:
> > +    items:
> > +      - const: main
> > +      - const: rtc
> > +
> > +  interrupts:
> > +    maxItems: 1
> > +
> > +  renesas,rtc-enabled:
> > +    description:
> > +      To indicate RTC is enabled on the PMIC.
> 
> "Enabled" by who or what? This looks like some policy, so Devicetree is not
> a place for it.

It is based on system design. System designers may chose not to populate built-in RTC by
grounding XIN and XOUT pins.

Do we need to add this info in description to make it clear??

Cheers,
Biju

> 
> > +    type: boolean
> > +
> > +required:
> > +  - compatible
> > +  - reg
> 
> 
> Best regards,
> Krzysztof


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

* Re: [PATCH v2 1/5] dt-bindings: mfd: Add Renesas RAA215300 PMIC bindings
  2023-05-05 18:21     ` Biju Das
@ 2023-05-05 18:32       ` Krzysztof Kozlowski
  0 siblings, 0 replies; 18+ messages in thread
From: Krzysztof Kozlowski @ 2023-05-05 18:32 UTC (permalink / raw)
  To: Biju Das, Lee Jones, Rob Herring, Krzysztof Kozlowski
  Cc: Geert Uytterhoeven, Magnus Damm, devicetree, linux-renesas-soc,
	Fabrizio Castro

On 05/05/2023 20:21, Biju Das wrote:
>>> +  reg:
>>> +    minItems: 1
>>> +    maxItems: 2
>>> +
>>> +  reg-names:
>>> +    items:
>>> +      - const: main
>>> +      - const: rtc
>>> +
>>> +  interrupts:
>>> +    maxItems: 1
>>> +
>>> +  renesas,rtc-enabled:
>>> +    description:
>>> +      To indicate RTC is enabled on the PMIC.
>>
>> "Enabled" by who or what? This looks like some policy, so Devicetree is not
>> a place for it.
> 
> It is based on system design. System designers may chose not to populate built-in RTC by
> grounding XIN and XOUT pins.
> 
> Do we need to add this info in description to make it clear??

Yes, this would solve my question, so please include it.


Best regards,
Krzysztof


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

* RE: [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300 RTC driver
  2023-05-05 17:25 ` [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300 RTC driver Biju Das
@ 2023-05-09  7:06   ` Biju Das
  2023-05-09  7:10     ` Geert Uytterhoeven
  0 siblings, 1 reply; 18+ messages in thread
From: Biju Das @ 2023-05-09  7:06 UTC (permalink / raw)
  To: Lee Jones, Alexandre Belloni, Geert Uytterhoeven
  Cc: Alessandro Zummo, Magnus Damm, linux-renesas-soc, Fabrizio Castro

Hi All,

> Subject: [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300 RTC driver
> 
> Currently, it is not possible to instantiate the i2c client driver using MFD
> cell as it is not a platform driver. Add support for Renesas PMIC
> RAA215300 RTC platform driver, so that it can be instantiated by MFD API.
> The rtc device is created by using i2c_new_ancillary_device() and it
> register as the rtc device by the helper function provided by
> rtc-isl2108 driver.

Not sure this platform driver has to be placed in RTC subsystem rather than MFD subsystem
as PMIC MFD driver, can instantiate it using MFD cell??

The advantage is the header file[1](isl1208.h) will be local to RTC subsystem compared
to across subsystem (include/linux/rtc/isl1208.h) and thereby avoids subsystem dependencies.

[1]
https://lore.kernel.org/linux-renesas-soc/20230505172530.357455-4-biju.das.jz@bp.renesas.com/T/#u

Cheers,
Biju

> 
> The PMIC driver enables RTC device and share the PMIC revision to RTC
> platform driver.
> 
> Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
> ---
> v2:
>  * New patch
> ---
>  drivers/mfd/Kconfig         |  7 +++++
>  drivers/mfd/Makefile        |  1 +
>  drivers/mfd/raa215300-rtc.c | 52 +++++++++++++++++++++++++++++++++++++
>  drivers/mfd/raa215300.c     | 38 ++++++++++++++++++++++++---
>  4 files changed, 95 insertions(+), 3 deletions(-)  create mode 100644
> drivers/mfd/raa215300-rtc.c
> 
> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index
> 9071b0f27b62..cec20c1f143d 100644
> --- a/drivers/mfd/Kconfig
> +++ b/drivers/mfd/Kconfig
> @@ -318,6 +318,13 @@ config PMIC_RAA215300
>  	help
>  	  Support for the Renesas RAA215300 PMIC.
> 
> +config PMIC_RAA215300_RTC
> +	tristate "Renesas RAA215300 RTC driver"
> +	depends on PMIC_RAA215300
> +	select RTC_DRV_ISL1208
> +	help
> +	  Select this to get support for the Renesas RAA215300 RTC
> +
>  config PMIC_DA903X
>  	bool "Dialog Semiconductor DA9030/DA9034 PMIC Support"
>  	depends on I2C=y
> diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index
> d9c601120bfd..ed4b760e564e 100644
> --- a/drivers/mfd/Makefile
> +++ b/drivers/mfd/Makefile
> @@ -127,6 +127,7 @@ obj-$(CONFIG_MCP_UCB1200)	+= ucb1x00-assabet.o
>  endif
> 
>  obj-$(CONFIG_PMIC_RAA215300)	+= raa215300.o
> +obj-$(CONFIG_PMIC_RAA215300_RTC)	+= raa215300-rtc.o
> 
>  obj-$(CONFIG_PMIC_DA903X)	+= da903x.o
> 
> diff --git a/drivers/mfd/raa215300-rtc.c b/drivers/mfd/raa215300-rtc.c new
> file mode 100644 index 000000000000..309ed34d6cd7
> --- /dev/null
> +++ b/drivers/mfd/raa215300-rtc.c
> @@ -0,0 +1,52 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Renesas RAA215300 RTC Driver
> + *
> + * Copyright (C) 2023 Renesas Electronics Corporation  */
> +
> +#include <linux/err.h>
> +#include <linux/i2c.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/rtc/isl1208.h>
> +
> +#define RAA215300_RTC_DEFAULT_ADDR 0x6f
> +
> +static void raa215300_rtc_unregister_device(void *data) {
> +	i2c_unregister_device(data);
> +}
> +
> +static int raa215300_rtc_probe(struct platform_device *pdev) {
> +	unsigned int *pmic_version = dev_get_drvdata(pdev->dev.parent);
> +	struct i2c_client *client;
> +	int ret;
> +
> +	client = i2c_new_ancillary_device(to_i2c_client(pdev->dev.parent),
> +					  "rtc", RAA215300_RTC_DEFAULT_ADDR);
> +	if (IS_ERR(client))
> +		return PTR_ERR(client);
> +
> +	ret = devm_add_action_or_reset(&pdev->dev,
> +				       raa215300_rtc_unregister_device, client);
> +	if (ret < 0)
> +		return ret;
> +
> +	return raa215300_rtc_probe_helper(client, *pmic_version); }
> +
> +static struct platform_driver raa215300_rtc_driver = {
> +	.probe = raa215300_rtc_probe,
> +	.driver = {
> +		.name = "raa215300-rtc",
> +	},
> +};
> +module_platform_driver(raa215300_rtc_driver);
> +
> +MODULE_DESCRIPTION("Renesas RAA215300 MFD RTC Driver");
> +MODULE_ALIAS("platform:raa215300-rtc");
> +MODULE_AUTHOR("Biju Das <biju.das.jz@bp.renesas.com>");
> +MODULE_LICENSE("GPL");
> +MODULE_SOFTDEP("post: rtc_isl1208");
> diff --git a/drivers/mfd/raa215300.c b/drivers/mfd/raa215300.c index
> 5cdd3213e99c..c8bdf96b203f 100644
> --- a/drivers/mfd/raa215300.c
> +++ b/drivers/mfd/raa215300.c
> @@ -8,6 +8,7 @@
>  #include <linux/err.h>
>  #include <linux/i2c.h>
>  #include <linux/module.h>
> +#include <linux/mfd/core.h>
>  #include <linux/of.h>
>  #include <linux/regmap.h>
> 
> @@ -29,13 +30,26 @@ static const struct regmap_config
> raa215300_regmap_config = {
>  	.cache_type = REGCACHE_FLAT,
>  };
> 
> +static const struct mfd_cell raa215300_rtc_dev[] = {
> +	{ .name = "raa215300-rtc" }
> +};
> +
> +static void raa215300_remove_devices(void *data) {
> +	mfd_remove_devices(data);
> +}
> +
>  static int raa215300_i2c_probe(struct i2c_client *client)  {
>  	struct device *dev = &client->dev;
> -	unsigned int pmic_version;
> +	unsigned int *pmic_version;
>  	struct regmap *regmap;
>  	int ret;
> 
> +	pmic_version = devm_kzalloc(dev, sizeof(*pmic_version), GFP_KERNEL);
> +	if (!pmic_version)
> +		return -ENOMEM;
> +
>  	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
>  		return -EOPNOTSUPP;
> 
> @@ -44,11 +58,29 @@ static int raa215300_i2c_probe(struct i2c_client
> *client)
>  		return dev_err_probe(dev, PTR_ERR(regmap),
>  				     "regmap i2c init failed\n");
> 
> -	ret = regmap_read(regmap, RAA215300_HW_REV, &pmic_version);
> +	ret = regmap_read(regmap, RAA215300_HW_REV, pmic_version);
>  	if (ret < 0)
>  		return dev_err_probe(dev, ret, "HW rev read failed\n");
> 
> -	dev_dbg(dev, "RAA215300 PMIC version 0x%04x\n", pmic_version);
> +	dev_dbg(dev, "RAA215300 PMIC version 0x%04x\n", *pmic_version);
> +	dev_set_drvdata(dev, pmic_version);
> +
> +	if (of_property_read_bool(dev->of_node, "renesas,rtc-enabled"))  {
> +		/* Enable RTC block */
> +		regmap_update_bits(regmap, RAA215300_REG_BLOCK_EN,
> +				   RAA215300_REG_BLOCK_EN_RTC_EN,
> +				   RAA215300_REG_BLOCK_EN_RTC_EN);
> +
> +		ret = mfd_add_devices(dev, 0, raa215300_rtc_dev,
> +				      ARRAY_SIZE(raa215300_rtc_dev), NULL,
> +				      0, NULL);
> +		if (ret < 0)
> +			return ret;
> +
> +		ret = devm_add_action_or_reset(dev, raa215300_remove_devices,
> dev);
> +		if (ret < 0)
> +			return ret;
> +	}
> 
>  	return 0;
>  }
> --
> 2.25.1


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

* Re: [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300 RTC driver
  2023-05-09  7:06   ` Biju Das
@ 2023-05-09  7:10     ` Geert Uytterhoeven
  2023-05-09  7:35       ` Biju Das
  0 siblings, 1 reply; 18+ messages in thread
From: Geert Uytterhoeven @ 2023-05-09  7:10 UTC (permalink / raw)
  To: Biju Das
  Cc: Lee Jones, Alexandre Belloni, Geert Uytterhoeven,
	Alessandro Zummo, Magnus Damm, linux-renesas-soc,
	Fabrizio Castro

Hi Biju,

On Tue, May 9, 2023 at 9:06 AM Biju Das <biju.das.jz@bp.renesas.com> wrote:
> > Subject: [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300 RTC driver
> >
> > Currently, it is not possible to instantiate the i2c client driver using MFD
> > cell as it is not a platform driver. Add support for Renesas PMIC
> > RAA215300 RTC platform driver, so that it can be instantiated by MFD API.
> > The rtc device is created by using i2c_new_ancillary_device() and it
> > register as the rtc device by the helper function provided by
> > rtc-isl2108 driver.
>
> Not sure this platform driver has to be placed in RTC subsystem rather than MFD subsystem
> as PMIC MFD driver, can instantiate it using MFD cell??

Can't you just instantiate the i2c ancillary device from the PMIC driver,
and drop the new mfd and platform rtc drivers?

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* RE: [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300 RTC driver
  2023-05-09  7:10     ` Geert Uytterhoeven
@ 2023-05-09  7:35       ` Biju Das
  2023-05-09  9:03         ` Geert Uytterhoeven
  0 siblings, 1 reply; 18+ messages in thread
From: Biju Das @ 2023-05-09  7:35 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Lee Jones, Alexandre Belloni, Geert Uytterhoeven,
	Alessandro Zummo, Magnus Damm, linux-renesas-soc,
	Fabrizio Castro

Hi Geert,

Thanks for the feedback.

> Subject: Re: [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300 RTC driver
> 
> Hi Biju,
> 
> On Tue, May 9, 2023 at 9:06 AM Biju Das <biju.das.jz@bp.renesas.com> wrote:
> > > Subject: [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300 RTC driver
> > >
> > > Currently, it is not possible to instantiate the i2c client driver
> > > using MFD cell as it is not a platform driver. Add support for
> > > Renesas PMIC
> > > RAA215300 RTC platform driver, so that it can be instantiated by MFD
> API.
> > > The rtc device is created by using i2c_new_ancillary_device() and it
> > > register as the rtc device by the helper function provided by
> > > rtc-isl2108 driver.
> >
> > Not sure this platform driver has to be placed in RTC subsystem rather
> > than MFD subsystem as PMIC MFD driver, can instantiate it using MFD cell??
> 
> Can't you just instantiate the i2c ancillary device from the PMIC driver,
> and drop the new mfd and platform rtc drivers?

Yes, it is possible.

The only reason MFD is used for future expansion like adding support for

1) battery charger
Or
2) regulator

In that case, we can share regmap to sub devices. But these drivers are not currently planned.

Apart from that,

1) It avoids subsystem dependencies, ie, PMIC driver directly calling rtc driver
   for registering RTC device.

2) I guess, the current split will also give some modular design.
   We have a control to enable or disable the driver.
   ie, Enable the driver PMIC with RTC enabled and
   disable the driver PMIC with RTC not enabled(ie, XIN/XOUT grounded) in the system design
   by controlling the config "PMIC_RAA215300_RTC".

These are the reasons for creating MFD driver and platform device.

I may be totally wrong. Please correct me if that is the case.

Cheers,
Biju


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

* Re: [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300 RTC driver
  2023-05-09  7:35       ` Biju Das
@ 2023-05-09  9:03         ` Geert Uytterhoeven
  2023-05-09  9:06           ` Geert Uytterhoeven
  2023-05-09  9:32           ` Biju Das
  0 siblings, 2 replies; 18+ messages in thread
From: Geert Uytterhoeven @ 2023-05-09  9:03 UTC (permalink / raw)
  To: Biju Das
  Cc: Lee Jones, Alexandre Belloni, Geert Uytterhoeven,
	Alessandro Zummo, Magnus Damm, linux-renesas-soc,
	Fabrizio Castro

Hi Biju,

On Tue, May 9, 2023 at 9:35 AM Biju Das <biju.das.jz@bp.renesas.com> wrote:
> > Subject: Re: [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300 RTC driver
> > On Tue, May 9, 2023 at 9:06 AM Biju Das <biju.das.jz@bp.renesas.com> wrote:
> > > > Subject: [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300 RTC driver
> > > >
> > > > Currently, it is not possible to instantiate the i2c client driver
> > > > using MFD cell as it is not a platform driver. Add support for
> > > > Renesas PMIC
> > > > RAA215300 RTC platform driver, so that it can be instantiated by MFD
> > API.
> > > > The rtc device is created by using i2c_new_ancillary_device() and it
> > > > register as the rtc device by the helper function provided by
> > > > rtc-isl2108 driver.
> > >
> > > Not sure this platform driver has to be placed in RTC subsystem rather
> > > than MFD subsystem as PMIC MFD driver, can instantiate it using MFD cell??
> >
> > Can't you just instantiate the i2c ancillary device from the PMIC driver,
> > and drop the new mfd and platform rtc drivers?
>
> Yes, it is possible.
>
> The only reason MFD is used for future expansion like adding support for
>
> 1) battery charger
> Or
> 2) regulator

I'd just start with a skeleton regulator ("PMIC") driver...

> In that case, we can share regmap to sub devices. But these drivers are not currently planned.
>
> Apart from that,
>
> 1) It avoids subsystem dependencies, ie, PMIC driver directly calling rtc driver
>    for registering RTC device.

You mean the direct call into raa215300_rtc_probe_helper()?
I think that can be solved by enhancing i2c_new_ancillary_device() to
take a proper device name, instead of using "dummy"?

> 2) I guess, the current split will also give some modular design.
>    We have a control to enable or disable the driver.
>    ie, Enable the driver PMIC with RTC enabled and
>    disable the driver PMIC with RTC not enabled(ie, XIN/XOUT grounded) in the system design
>    by controlling the config "PMIC_RAA215300_RTC".

You already have CONFIG_RTC_DRV_ISL1208, and look at
"renesas,rtc-enabled" before activating the RTC?

> These are the reasons for creating MFD driver and platform device.
>
> I may be totally wrong. Please correct me if that is the case.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300 RTC driver
  2023-05-09  9:03         ` Geert Uytterhoeven
@ 2023-05-09  9:06           ` Geert Uytterhoeven
  2023-05-09  9:32           ` Biju Das
  1 sibling, 0 replies; 18+ messages in thread
From: Geert Uytterhoeven @ 2023-05-09  9:06 UTC (permalink / raw)
  To: Biju Das
  Cc: Lee Jones, Alexandre Belloni, Alessandro Zummo, Magnus Damm,
	linux-renesas-soc, Fabrizio Castro, Wolfram Sang

CC Wolfram

On Tue, May 9, 2023 at 11:03 AM Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> On Tue, May 9, 2023 at 9:35 AM Biju Das <biju.das.jz@bp.renesas.com> wrote:
> > > Subject: Re: [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300 RTC driver
> > > On Tue, May 9, 2023 at 9:06 AM Biju Das <biju.das.jz@bp.renesas.com> wrote:
> > > > > Subject: [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300 RTC driver
> > > > >
> > > > > Currently, it is not possible to instantiate the i2c client driver
> > > > > using MFD cell as it is not a platform driver. Add support for
> > > > > Renesas PMIC
> > > > > RAA215300 RTC platform driver, so that it can be instantiated by MFD
> > > API.
> > > > > The rtc device is created by using i2c_new_ancillary_device() and it
> > > > > register as the rtc device by the helper function provided by
> > > > > rtc-isl2108 driver.
> > > >
> > > > Not sure this platform driver has to be placed in RTC subsystem rather
> > > > than MFD subsystem as PMIC MFD driver, can instantiate it using MFD cell??
> > >
> > > Can't you just instantiate the i2c ancillary device from the PMIC driver,
> > > and drop the new mfd and platform rtc drivers?
> >
> > Yes, it is possible.
> >
> > The only reason MFD is used for future expansion like adding support for
> >
> > 1) battery charger
> > Or
> > 2) regulator
>
> I'd just start with a skeleton regulator ("PMIC") driver...
>
> > In that case, we can share regmap to sub devices. But these drivers are not currently planned.
> >
> > Apart from that,
> >
> > 1) It avoids subsystem dependencies, ie, PMIC driver directly calling rtc driver
> >    for registering RTC device.
>
> You mean the direct call into raa215300_rtc_probe_helper()?
> I think that can be solved by enhancing i2c_new_ancillary_device() to
> take a proper device name, instead of using "dummy"?
>
> > 2) I guess, the current split will also give some modular design.
> >    We have a control to enable or disable the driver.
> >    ie, Enable the driver PMIC with RTC enabled and
> >    disable the driver PMIC with RTC not enabled(ie, XIN/XOUT grounded) in the system design
> >    by controlling the config "PMIC_RAA215300_RTC".
>
> You already have CONFIG_RTC_DRV_ISL1208, and look at
> "renesas,rtc-enabled" before activating the RTC?
>
> > These are the reasons for creating MFD driver and platform device.
> >
> > I may be totally wrong. Please correct me if that is the case.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* RE: [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300 RTC driver
  2023-05-09  9:03         ` Geert Uytterhoeven
  2023-05-09  9:06           ` Geert Uytterhoeven
@ 2023-05-09  9:32           ` Biju Das
  2023-05-09  9:39             ` Geert Uytterhoeven
  1 sibling, 1 reply; 18+ messages in thread
From: Biju Das @ 2023-05-09  9:32 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Lee Jones, Alexandre Belloni, Geert Uytterhoeven,
	Alessandro Zummo, Magnus Damm, linux-renesas-soc,
	Fabrizio Castro, Wolfram Sang

Hi Geert,

> Subject: Re: [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300 RTC driver
> 
> Hi Biju,
> 
> On Tue, May 9, 2023 at 9:35 AM Biju Das <biju.das.jz@bp.renesas.com> wrote:
> > > Subject: Re: [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300 RTC
> > > driver On Tue, May 9, 2023 at 9:06 AM Biju Das
> <biju.das.jz@bp.renesas.com> wrote:
> > > > > Subject: [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300 RTC
> > > > > driver
> > > > >
> > > > > Currently, it is not possible to instantiate the i2c client
> > > > > driver using MFD cell as it is not a platform driver. Add
> > > > > support for Renesas PMIC
> > > > > RAA215300 RTC platform driver, so that it can be instantiated by
> > > > > MFD
> > > API.
> > > > > The rtc device is created by using i2c_new_ancillary_device()
> > > > > and it register as the rtc device by the helper function
> > > > > provided by
> > > > > rtc-isl2108 driver.
> > > >
> > > > Not sure this platform driver has to be placed in RTC subsystem
> > > > rather than MFD subsystem as PMIC MFD driver, can instantiate it using
> MFD cell??
> > >
> > > Can't you just instantiate the i2c ancillary device from the PMIC
> > > driver, and drop the new mfd and platform rtc drivers?
> >
> > Yes, it is possible.
> >
> > The only reason MFD is used for future expansion like adding support
> > for
> >
> > 1) battery charger
> > Or
> > 2) regulator
> 
> I'd just start with a skeleton regulator ("PMIC") driver...
> 
> > In that case, we can share regmap to sub devices. But these drivers are
> not currently planned.
> >
> > Apart from that,
> >
> > 1) It avoids subsystem dependencies, ie, PMIC driver directly calling rtc
> driver
> >    for registering RTC device.
> 
> You mean the direct call into raa215300_rtc_probe_helper()?

Yes, indeed.

> I think that can be solved by enhancing i2c_new_ancillary_device() to take a
> proper device name, instead of using "dummy"?

Geert, Wolfram, 

Any pointers for instantiating i2c_client device(for eg: rtc_isl1208.c)
by enhancing i2c_new_ancillary_device() api? 

Apart for this, since a single compatible(the pmic one) is used, 

In rtc device probe, How do we identify this PMIC RTC device and use the "TYPE_ISL1208" config
in RTC driver, once we instantiate RTC device?


> 
> > 2) I guess, the current split will also give some modular design.
> >    We have a control to enable or disable the driver.
> >    ie, Enable the driver PMIC with RTC enabled and
> >    disable the driver PMIC with RTC not enabled(ie, XIN/XOUT grounded) in
> the system design
> >    by controlling the config "PMIC_RAA215300_RTC".
> 
> You already have CONFIG_RTC_DRV_ISL1208, and look at "renesas,rtc-enabled"
> before activating the RTC?

I agree. this will take care. I just added this CONFIG, so that we can have
Built-in PMIC driver and RTC module driver??

Cheers,
Biju

> 
> > These are the reasons for creating MFD driver and platform device.
> >
> > I may be totally wrong. Please correct me if that is the case.

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

* Re: [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300 RTC driver
  2023-05-09  9:32           ` Biju Das
@ 2023-05-09  9:39             ` Geert Uytterhoeven
  2023-05-09 17:05               ` Biju Das
  0 siblings, 1 reply; 18+ messages in thread
From: Geert Uytterhoeven @ 2023-05-09  9:39 UTC (permalink / raw)
  To: Biju Das
  Cc: Lee Jones, Alexandre Belloni, Alessandro Zummo, Magnus Damm,
	linux-renesas-soc, Fabrizio Castro, Wolfram Sang

Hi Biju,

On Tue, May 9, 2023 at 11:32 AM Biju Das <biju.das.jz@bp.renesas.com> wrote:
> > Subject: Re: [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300 RTC driver
> > On Tue, May 9, 2023 at 9:35 AM Biju Das <biju.das.jz@bp.renesas.com> wrote:
> > > > Subject: Re: [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300 RTC
> > > > driver On Tue, May 9, 2023 at 9:06 AM Biju Das
> > <biju.das.jz@bp.renesas.com> wrote:
> > > > > > Subject: [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300 RTC
> > > > > > driver
> > > > > >
> > > > > > Currently, it is not possible to instantiate the i2c client
> > > > > > driver using MFD cell as it is not a platform driver. Add
> > > > > > support for Renesas PMIC
> > > > > > RAA215300 RTC platform driver, so that it can be instantiated by
> > > > > > MFD
> > > > API.
> > > > > > The rtc device is created by using i2c_new_ancillary_device()
> > > > > > and it register as the rtc device by the helper function
> > > > > > provided by
> > > > > > rtc-isl2108 driver.
> > > > >
> > > > > Not sure this platform driver has to be placed in RTC subsystem
> > > > > rather than MFD subsystem as PMIC MFD driver, can instantiate it using
> > MFD cell??
> > > >
> > > > Can't you just instantiate the i2c ancillary device from the PMIC
> > > > driver, and drop the new mfd and platform rtc drivers?
> > >
> > > Yes, it is possible.
> > >
> > > The only reason MFD is used for future expansion like adding support
> > > for
> > >
> > > 1) battery charger
> > > Or
> > > 2) regulator
> >
> > I'd just start with a skeleton regulator ("PMIC") driver...
> >
> > > In that case, we can share regmap to sub devices. But these drivers are
> > not currently planned.
> > >
> > > Apart from that,
> > >
> > > 1) It avoids subsystem dependencies, ie, PMIC driver directly calling rtc
> > driver
> > >    for registering RTC device.
> >
> > You mean the direct call into raa215300_rtc_probe_helper()?
>
> Yes, indeed.
>
> > I think that can be solved by enhancing i2c_new_ancillary_device() to take a
> > proper device name, instead of using "dummy"?
>
> Geert, Wolfram,
>
> Any pointers for instantiating i2c_client device(for eg: rtc_isl1208.c)
> by enhancing i2c_new_ancillary_device() api?
>
> Apart for this, since a single compatible(the pmic one) is used,
>
> In rtc device probe, How do we identify this PMIC RTC device and use the "TYPE_ISL1208" config
> in RTC driver, once we instantiate RTC device?

You create ancillary devices with different names, based on the detected
PMIC version, and add new types for them to the isl1208 driver?

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* RE: [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300 RTC driver
  2023-05-09  9:39             ` Geert Uytterhoeven
@ 2023-05-09 17:05               ` Biju Das
  2023-05-13 14:34                 ` Biju Das
  0 siblings, 1 reply; 18+ messages in thread
From: Biju Das @ 2023-05-09 17:05 UTC (permalink / raw)
  To: Geert Uytterhoeven, Wolfram Sang
  Cc: Lee Jones, Alexandre Belloni, Alessandro Zummo, Magnus Damm,
	linux-renesas-soc, Fabrizio Castro

Hi Geert,

Thanks for the feedback.

> -----Original Message-----
> From: Geert Uytterhoeven <geert@linux-m68k.org>
> Sent: Tuesday, May 9, 2023 10:40 AM
> To: Biju Das <biju.das.jz@bp.renesas.com>
> Cc: Lee Jones <lee@kernel.org>; Alexandre Belloni
> <alexandre.belloni@bootlin.com>; Alessandro Zummo <a.zummo@towertech.it>;
> Magnus Damm <magnus.damm@gmail.com>; linux-renesas-soc@vger.kernel.org;
> Fabrizio Castro <fabrizio.castro.jz@renesas.com>; Wolfram Sang <wsa-
> dev@sang-engineering.com>
> Subject: Re: [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300 RTC driver
> 
> Hi Biju,
> 
> On Tue, May 9, 2023 at 11:32 AM Biju Das <biju.das.jz@bp.renesas.com> wrote:
> > > Subject: Re: [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300 RTC
> > > driver On Tue, May 9, 2023 at 9:35 AM Biju Das
> <biju.das.jz@bp.renesas.com> wrote:
> > > > > Subject: Re: [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300 RTC
> > > > > driver On Tue, May 9, 2023 at 9:06 AM Biju Das
> > > <biju.das.jz@bp.renesas.com> wrote:
> > > > > > > Subject: [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300 RTC
> > > > > > > driver
> > > > > > >
> > > > > > > Currently, it is not possible to instantiate the i2c client
> > > > > > > driver using MFD cell as it is not a platform driver. Add
> > > > > > > support for Renesas PMIC
> > > > > > > RAA215300 RTC platform driver, so that it can be
> > > > > > > instantiated by MFD
> > > > > API.
> > > > > > > The rtc device is created by using
> > > > > > > i2c_new_ancillary_device() and it register as the rtc device
> > > > > > > by the helper function provided by
> > > > > > > rtc-isl2108 driver.
> > > > > >
> > > > > > Not sure this platform driver has to be placed in RTC
> > > > > > subsystem rather than MFD subsystem as PMIC MFD driver, can
> > > > > > instantiate it using
> > > MFD cell??
> > > > >
> > > > > Can't you just instantiate the i2c ancillary device from the
> > > > > PMIC driver, and drop the new mfd and platform rtc drivers?
> > > >
> > > > Yes, it is possible.
> > > >
> > > > The only reason MFD is used for future expansion like adding
> > > > support for
> > > >
> > > > 1) battery charger
> > > > Or
> > > > 2) regulator
> > >
> > > I'd just start with a skeleton regulator ("PMIC") driver...
> > >
> > > > In that case, we can share regmap to sub devices. But these
> > > > drivers are
> > > not currently planned.
> > > >
> > > > Apart from that,
> > > >
> > > > 1) It avoids subsystem dependencies, ie, PMIC driver directly
> > > > calling rtc
> > > driver
> > > >    for registering RTC device.
> > >
> > > You mean the direct call into raa215300_rtc_probe_helper()?
> >
> > Yes, indeed.
> >
> > > I think that can be solved by enhancing i2c_new_ancillary_device()
> > > to take a proper device name, instead of using "dummy"?
> >
> > Geert, Wolfram,
> >
> > Any pointers for instantiating i2c_client device(for eg:
> > rtc_isl1208.c) by enhancing i2c_new_ancillary_device() api?
> >
> > Apart for this, since a single compatible(the pmic one) is used,
> >
> > In rtc device probe, How do we identify this PMIC RTC device and use
> > the "TYPE_ISL1208" config in RTC driver, once we instantiate RTC device?
> 
> You create ancillary devices with different names, based on the detected
> PMIC version, and add new types for them to the isl1208 driver?

OK, I have prototyped this.

Wolfram,

What is your opinion, should I enhance "i2c_new_ancillary_device" like
below[1]?  or directly call "i2c_new_client_device" from PMIC driver to
instantiate the client device?

Please let me know.

[1]
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index ae3af738b03f..79808e852f2f 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -1122,15 +1122,17 @@ EXPORT_SYMBOL_GPL(devm_i2c_new_dummy_device);
  * @client: Handle to the primary client
  * @name: Handle to specify which secondary address to get
  * @default_addr: Used as a fallback if no secondary address was specified
+ * @aux_device_name: Optional ancillary device name
  * Context: can sleep
  *
  * I2C clients can be composed of multiple I2C slaves bound together in a single
  * component. The I2C client driver then binds to the master I2C slave and needs
- * to create I2C dummy clients to communicate with all the other slaves.
+ * to create I2C ancillary clients to communicate with all the other slaves.
  *
- * This function creates and returns an I2C dummy client whose I2C address is
- * retrieved from the platform firmware based on the given slave name. If no
- * address is specified by the firmware default_addr is used.
+ * This function creates and returns an I2C ancillary client whose I2C address
+ * is retrieved from the platform firmware based on the given slave name. If no
+ * address is specified by the firmware default_addr is used. if no aux_device_
+ * name is specified by the firmware, it will create i2c dummy client.
  *
  * On DT-based platforms the address is retrieved from the "reg" property entry
  * cell whose "reg-names" value matches the slave name.
@@ -1139,10 +1141,12 @@ EXPORT_SYMBOL_GPL(devm_i2c_new_dummy_device);
  * i2c_unregister_device(); or an ERR_PTR to describe the error.
  */
 struct i2c_client *i2c_new_ancillary_device(struct i2c_client *client,
-						const char *name,
-						u16 default_addr)
+					    const char *name,
+					    u16 default_addr,
+					    const char *aux_device_name)
 {
 	struct device_node *np = client->dev.of_node;
+	struct i2c_client *i2c_aux_client;
 	u32 addr = default_addr;
 	int i;
 
@@ -1153,7 +1157,27 @@ struct i2c_client *i2c_new_ancillary_device(struct i2c_client *client,
 	}
 
 	dev_dbg(&client->adapter->dev, "Address for %s : 0x%x\n", name, addr);
-	return i2c_new_dummy_device(client->adapter, addr);
+
+	if (aux_device_name) {
+		struct i2c_board_info info;
+		size_t device_name_len = strlen(device_name);
+
+		if (aux_device_name_len > I2C_NAME_SIZE - 1) {
+			dev_err(&client->adapter->dev, "Invalid device name\n");
+			return ERR_PTR(-EINVAL);
+		}
+
+		memset(&info, 0, sizeof(struct i2c_board_info));
+
+		memcpy(info.type, device_name, device_name_len);
+		info.addr = addr;
+
+		i2c_aux_client = i2c_new_client_device(client->adapter, &info);
+	} else {
+		i2c_aux_client = i2c_new_dummy_device(client->adapter, addr);
+	}
+
+	return i2c_aux_client;
 }
 EXPORT_SYMBOL_GPL(i2c_new_ancillary_device);


Cheers,
Biju

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

* RE: [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300 RTC driver
  2023-05-09 17:05               ` Biju Das
@ 2023-05-13 14:34                 ` Biju Das
  0 siblings, 0 replies; 18+ messages in thread
From: Biju Das @ 2023-05-13 14:34 UTC (permalink / raw)
  To: Geert Uytterhoeven, Wolfram Sang
  Cc: Lee Jones, Alexandre Belloni, Alessandro Zummo, Magnus Damm,
	linux-renesas-soc, Fabrizio Castro

Hi Wolfram,

> -----Original Message-----
> From: Biju Das <biju.das.jz@bp.renesas.com>
> Sent: Tuesday, May 9, 2023 6:05 PM
> To: Geert Uytterhoeven <geert@linux-m68k.org>; Wolfram Sang <wsa-dev@sang-
> engineering.com>
> Cc: Lee Jones <lee@kernel.org>; Alexandre Belloni
> <alexandre.belloni@bootlin.com>; Alessandro Zummo <a.zummo@towertech.it>;
> Magnus Damm <magnus.damm@gmail.com>; linux-renesas-soc@vger.kernel.org;
> Fabrizio Castro <fabrizio.castro.jz@renesas.com>
> Subject: RE: [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300 RTC driver
> 
> Hi Geert,
> 
> Thanks for the feedback.
> 
> > -----Original Message-----
> > From: Geert Uytterhoeven <geert@linux-m68k.org>
> > Sent: Tuesday, May 9, 2023 10:40 AM
> > To: Biju Das <biju.das.jz@bp.renesas.com>
> > Cc: Lee Jones <lee@kernel.org>; Alexandre Belloni
> > <alexandre.belloni@bootlin.com>; Alessandro Zummo
> > <a.zummo@towertech.it>; Magnus Damm <magnus.damm@gmail.com>;
> > linux-renesas-soc@vger.kernel.org;
> > Fabrizio Castro <fabrizio.castro.jz@renesas.com>; Wolfram Sang <wsa-
> > dev@sang-engineering.com>
> > Subject: Re: [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300 RTC driver
> >
> > Hi Biju,
> >
> > On Tue, May 9, 2023 at 11:32 AM Biju Das <biju.das.jz@bp.renesas.com>
> wrote:
> > > > Subject: Re: [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300 RTC
> > > > driver On Tue, May 9, 2023 at 9:35 AM Biju Das
> > <biju.das.jz@bp.renesas.com> wrote:
> > > > > > Subject: Re: [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300
> > > > > > RTC driver On Tue, May 9, 2023 at 9:06 AM Biju Das
> > > > <biju.das.jz@bp.renesas.com> wrote:
> > > > > > > > Subject: [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300
> > > > > > > > RTC driver
> > > > > > > >
> > > > > > > > Currently, it is not possible to instantiate the i2c
> > > > > > > > client driver using MFD cell as it is not a platform
> > > > > > > > driver. Add support for Renesas PMIC
> > > > > > > > RAA215300 RTC platform driver, so that it can be
> > > > > > > > instantiated by MFD
> > > > > > API.
> > > > > > > > The rtc device is created by using
> > > > > > > > i2c_new_ancillary_device() and it register as the rtc
> > > > > > > > device by the helper function provided by
> > > > > > > > rtc-isl2108 driver.
> > > > > > >
> > > > > > > Not sure this platform driver has to be placed in RTC
> > > > > > > subsystem rather than MFD subsystem as PMIC MFD driver, can
> > > > > > > instantiate it using
> > > > MFD cell??
> > > > > >
> > > > > > Can't you just instantiate the i2c ancillary device from the
> > > > > > PMIC driver, and drop the new mfd and platform rtc drivers?
> > > > >
> > > > > Yes, it is possible.
> > > > >
> > > > > The only reason MFD is used for future expansion like adding
> > > > > support for
> > > > >
> > > > > 1) battery charger
> > > > > Or
> > > > > 2) regulator
> > > >
> > > > I'd just start with a skeleton regulator ("PMIC") driver...
> > > >
> > > > > In that case, we can share regmap to sub devices. But these
> > > > > drivers are
> > > > not currently planned.
> > > > >
> > > > > Apart from that,
> > > > >
> > > > > 1) It avoids subsystem dependencies, ie, PMIC driver directly
> > > > > calling rtc
> > > > driver
> > > > >    for registering RTC device.
> > > >
> > > > You mean the direct call into raa215300_rtc_probe_helper()?
> > >
> > > Yes, indeed.
> > >
> > > > I think that can be solved by enhancing i2c_new_ancillary_device()
> > > > to take a proper device name, instead of using "dummy"?
> > >
> > > Geert, Wolfram,
> > >
> > > Any pointers for instantiating i2c_client device(for eg:
> > > rtc_isl1208.c) by enhancing i2c_new_ancillary_device() api?
> > >
> > > Apart for this, since a single compatible(the pmic one) is used,
> > >
> > > In rtc device probe, How do we identify this PMIC RTC device and use
> > > the "TYPE_ISL1208" config in RTC driver, once we instantiate RTC device?
> >
> > You create ancillary devices with different names, based on the
> > detected PMIC version, and add new types for them to the isl1208 driver?
> 
> OK, I have prototyped this.
> 
> Wolfram,
> 
> What is your opinion, should I enhance "i2c_new_ancillary_device" like
> below[1]?  or directly call "i2c_new_client_device" from PMIC driver to
> instantiate the client device?

> 
> Please let me know.

I will post a proper patch based on [1], so that we can discuss it there.

Cheers,
Biju

> 
> [1]
> diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index
> ae3af738b03f..79808e852f2f 100644
> --- a/drivers/i2c/i2c-core-base.c
> +++ b/drivers/i2c/i2c-core-base.c
> @@ -1122,15 +1122,17 @@ EXPORT_SYMBOL_GPL(devm_i2c_new_dummy_device);
>   * @client: Handle to the primary client
>   * @name: Handle to specify which secondary address to get
>   * @default_addr: Used as a fallback if no secondary address was specified
> + * @aux_device_name: Optional ancillary device name
>   * Context: can sleep
>   *
>   * I2C clients can be composed of multiple I2C slaves bound together in a
> single
>   * component. The I2C client driver then binds to the master I2C slave and
> needs
> - * to create I2C dummy clients to communicate with all the other slaves.
> + * to create I2C ancillary clients to communicate with all the other
> slaves.
>   *
> - * This function creates and returns an I2C dummy client whose I2C address
> is
> - * retrieved from the platform firmware based on the given slave name. If
> no
> - * address is specified by the firmware default_addr is used.
> + * This function creates and returns an I2C ancillary client whose I2C
> + address
> + * is retrieved from the platform firmware based on the given slave
> + name. If no
> + * address is specified by the firmware default_addr is used. if no
> + aux_device_
> + * name is specified by the firmware, it will create i2c dummy client.
>   *
>   * On DT-based platforms the address is retrieved from the "reg" property
> entry
>   * cell whose "reg-names" value matches the slave name.
> @@ -1139,10 +1141,12 @@ EXPORT_SYMBOL_GPL(devm_i2c_new_dummy_device);
>   * i2c_unregister_device(); or an ERR_PTR to describe the error.
>   */
>  struct i2c_client *i2c_new_ancillary_device(struct i2c_client *client,
> -						const char *name,
> -						u16 default_addr)
> +					    const char *name,
> +					    u16 default_addr,
> +					    const char *aux_device_name)
>  {
>  	struct device_node *np = client->dev.of_node;
> +	struct i2c_client *i2c_aux_client;
>  	u32 addr = default_addr;
>  	int i;
> 
> @@ -1153,7 +1157,27 @@ struct i2c_client *i2c_new_ancillary_device(struct
> i2c_client *client,
>  	}
> 
>  	dev_dbg(&client->adapter->dev, "Address for %s : 0x%x\n", name, addr);
> -	return i2c_new_dummy_device(client->adapter, addr);
> +
> +	if (aux_device_name) {
> +		struct i2c_board_info info;
> +		size_t device_name_len = strlen(device_name);
> +
> +		if (aux_device_name_len > I2C_NAME_SIZE - 1) {
> +			dev_err(&client->adapter->dev, "Invalid device name\n");
> +			return ERR_PTR(-EINVAL);
> +		}
> +
> +		memset(&info, 0, sizeof(struct i2c_board_info));
> +
> +		memcpy(info.type, device_name, device_name_len);
> +		info.addr = addr;
> +
> +		i2c_aux_client = i2c_new_client_device(client->adapter, &info);
> +	} else {
> +		i2c_aux_client = i2c_new_dummy_device(client->adapter, addr);
> +	}
> +
> +	return i2c_aux_client;
>  }
>  EXPORT_SYMBOL_GPL(i2c_new_ancillary_device);
> 
> 
> Cheers,
> Biju

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

end of thread, other threads:[~2023-05-13 14:34 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-05 17:25 [PATCH v2 0/5] Add Renesas PMIC RAA215300 and built-in RTC support Biju Das
2023-05-05 17:25 ` [PATCH v2 1/5] dt-bindings: mfd: Add Renesas RAA215300 PMIC bindings Biju Das
2023-05-05 18:08   ` Krzysztof Kozlowski
2023-05-05 18:21     ` Biju Das
2023-05-05 18:32       ` Krzysztof Kozlowski
2023-05-05 17:25 ` [PATCH v2 2/5] mfd: Add Renesas PMIC RAA215300 driver Biju Das
2023-05-05 17:25 ` [PATCH v2 3/5] rtc: isl1208: Add support for the built-in RTC on the PMIC RAA215300 Biju Das
2023-05-05 17:25 ` [PATCH v2 4/5] mfd: Add Renesas PMIC RAA215300 RTC driver Biju Das
2023-05-09  7:06   ` Biju Das
2023-05-09  7:10     ` Geert Uytterhoeven
2023-05-09  7:35       ` Biju Das
2023-05-09  9:03         ` Geert Uytterhoeven
2023-05-09  9:06           ` Geert Uytterhoeven
2023-05-09  9:32           ` Biju Das
2023-05-09  9:39             ` Geert Uytterhoeven
2023-05-09 17:05               ` Biju Das
2023-05-13 14:34                 ` Biju Das
2023-05-05 17:25 ` [PATCH v2 5/5] arm64: dts: renesas: rzg2l-smarc-som: Enable PMIC and built-in RTC Biju Das

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.