linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] mfd: add tps6594x support for j7200 platform
@ 2022-08-05  6:43 Matt Ranostay
  2022-08-05  6:43 ` [PATCH 1/4] Documentation: tps6594x: Add DT bindings for the TPS6594x PMIC Matt Ranostay
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Matt Ranostay @ 2022-08-05  6:43 UTC (permalink / raw)
  To: lee, nm
  Cc: linux-rtc, linux-kernel, linux-arm-kernel, devicetree, Matt Ranostay

This patchset series adds support for the TPS6594x PMIC along with
initial support for its RTC, and poweroff sequence.

Additionally, add usage of the PMIC for the J7200 platform's device tree.

Keerthy (3):
  MFD: TPS6594x: Add new mfd device for TPS6594x PMIC
  rtc: rtc-tps6594x: Add support for TPS6594X PMIC RTC
  arm64: dts: ti: k3-j7200-common-proc-board: Add TPS6594x PMIC node

Matt Ranostay (1):
  Documentation: tps6594x: Add DT bindings for the TPS6594x PMIC

 .../devicetree/bindings/mfd/ti,tps6594x.yaml  |  53 +++++
 .../dts/ti/k3-j7200-common-proc-board.dts     |  16 ++
 drivers/mfd/Kconfig                           |  14 ++
 drivers/mfd/Makefile                          |   1 +
 drivers/mfd/tps6594x.c                        | 106 ++++++++++
 drivers/rtc/Kconfig                           |  10 +
 drivers/rtc/Makefile                          |   1 +
 drivers/rtc/rtc-tps6594x.c                    | 181 ++++++++++++++++++
 include/linux/mfd/tps6594x.h                  |  66 +++++++
 9 files changed, 448 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/ti,tps6594x.yaml
 create mode 100644 drivers/mfd/tps6594x.c
 create mode 100644 drivers/rtc/rtc-tps6594x.c
 create mode 100644 include/linux/mfd/tps6594x.h

-- 
2.36.1


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

* [PATCH 1/4] Documentation: tps6594x: Add DT bindings for the TPS6594x PMIC
  2022-08-05  6:43 [PATCH 0/4] mfd: add tps6594x support for j7200 platform Matt Ranostay
@ 2022-08-05  6:43 ` Matt Ranostay
  2022-08-05 14:14   ` Rob Herring
  2022-08-05  6:43 ` [PATCH 2/4] MFD: TPS6594x: Add new mfd device for " Matt Ranostay
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: Matt Ranostay @ 2022-08-05  6:43 UTC (permalink / raw)
  To: lee, nm
  Cc: linux-rtc, linux-kernel, linux-arm-kernel, devicetree, Matt Ranostay

Signed-off-by: Matt Ranostay <mranostay@ti.com>
---
 .../devicetree/bindings/mfd/ti,tps6594x.yaml  | 53 +++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/ti,tps6594x.yaml

diff --git a/Documentation/devicetree/bindings/mfd/ti,tps6594x.yaml b/Documentation/devicetree/bindings/mfd/ti,tps6594x.yaml
new file mode 100644
index 000000000000..9fd3af87a861
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/ti,tps6594x.yaml
@@ -0,0 +1,53 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/ti,tps65086.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: TPS6594x Power Management Integrated Circuit (PMIC)
+
+maintainers:
+  - Keerthy <j-keerthy@ti.com>
+
+properties:
+  compatible:
+    const: ti,tps6594x
+
+  reg:
+    const: 0x48
+    description: I2C slave address
+
+  ti,system-power-controller:
+    description: PMIC is controlling the system power.
+
+  rtc:
+    type: object
+    $ref: /schemas/rtc/rtc.yaml#
+    unevaluatedProperties: false
+    properties:
+      compatible:
+        const: ti,tps6594x-rtc
+
+additionalProperties: false
+
+required:
+  - compatible
+  - reg
+
+examples:
+  - |
+    i2c0 {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        pmic: pmic@48 {
+            compatible = "ti,tps6594x";
+            reg = <0x48>;
+
+            rtc {
+                compatible = "ti,tps6594x-rtc";
+            };
+        };
+    };
+
+...
-- 
2.36.1


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

* [PATCH 2/4] MFD: TPS6594x: Add new mfd device for TPS6594x PMIC
  2022-08-05  6:43 [PATCH 0/4] mfd: add tps6594x support for j7200 platform Matt Ranostay
  2022-08-05  6:43 ` [PATCH 1/4] Documentation: tps6594x: Add DT bindings for the TPS6594x PMIC Matt Ranostay
@ 2022-08-05  6:43 ` Matt Ranostay
  2022-08-10 11:27   ` Lee Jones
  2022-08-05  6:43 ` [PATCH 3/4] rtc: rtc-tps6594x: Add support for TPS6594X PMIC RTC Matt Ranostay
  2022-08-05  6:43 ` [PATCH 4/4] arm64: dts: ti: k3-j7200-common-proc-board: Add TPS6594x PMIC node Matt Ranostay
  3 siblings, 1 reply; 9+ messages in thread
From: Matt Ranostay @ 2022-08-05  6:43 UTC (permalink / raw)
  To: lee, nm
  Cc: linux-rtc, linux-kernel, linux-arm-kernel, devicetree, Keerthy,
	Matt Ranostay

From: Keerthy <j-keerthy@ti.com>

The TPS6594x chip is a PMIC, and contains the following components:

- Regulators
- GPIO controller
- RTC

However initially only RTC is supported.

Signed-off-by: Keerthy <j-keerthy@ti.com>
Signed-off-by: Matt Ranostay <mranostay@ti.com>
---
 drivers/mfd/Kconfig          |  14 +++++
 drivers/mfd/Makefile         |   1 +
 drivers/mfd/tps6594x.c       | 106 +++++++++++++++++++++++++++++++++++
 include/linux/mfd/tps6594x.h |  66 ++++++++++++++++++++++
 4 files changed, 187 insertions(+)
 create mode 100644 drivers/mfd/tps6594x.c
 create mode 100644 include/linux/mfd/tps6594x.h

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index abb58ab1a1a4..cfb5b3d66b76 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -1547,6 +1547,20 @@ config MFD_TI_LP873X
 	  This driver can also be built as a module. If so, the module
 	  will be called lp873x.
 
+config MFD_TPS6594X
+	tristate "TI TPS6594X Power Management IC"
+	depends on I2C
+	select MFD_CORE
+	select REGMAP_I2C
+	help
+	  If you say yes here then you get support for the TPS6594X series of
+	  Power Management Integrated Circuits (PMIC).
+	  These include voltage regulators, RTS, configurable
+	  General Purpose Outputs (GPO) that are used in portable devices.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called tps7694x.
+
 config MFD_TI_LP87565
 	tristate "TI LP87565 Power Management IC"
 	depends on I2C && OF
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 858cacf659d6..7ff6a8a57d55 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -105,6 +105,7 @@ obj-$(CONFIG_MFD_TPS65910)	+= tps65910.o
 obj-$(CONFIG_MFD_TPS65912)	+= tps65912-core.o
 obj-$(CONFIG_MFD_TPS65912_I2C)	+= tps65912-i2c.o
 obj-$(CONFIG_MFD_TPS65912_SPI)  += tps65912-spi.o
+obj-$(CONFIG_MFD_TPS6594X)	+= tps6594x.o
 obj-$(CONFIG_MENELAUS)		+= menelaus.o
 
 obj-$(CONFIG_TWL4030_CORE)	+= twl-core.o twl4030-irq.o twl6030-irq.o
diff --git a/drivers/mfd/tps6594x.c b/drivers/mfd/tps6594x.c
new file mode 100644
index 000000000000..519162cc1fbe
--- /dev/null
+++ b/drivers/mfd/tps6594x.c
@@ -0,0 +1,106 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * tps6594x.c  --  TI TPS6594x chip family multi-function driver
+ *
+ * Copyright (C) 2022 Texas Instruments Incorporated - https://www.ti.com/
+ *
+ * Author: Keerthy <j-keerthy@ti.com>
+ */
+
+#include <linux/interrupt.h>
+#include <linux/mfd/core.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/i2c.h>
+#include <linux/regmap.h>
+
+#include <linux/mfd/tps6594x.h>
+
+static const struct regmap_config tps6594x_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.max_register = TPS6594X_REG_MAX,
+};
+
+static const struct mfd_cell tps6594x_cells[] = {
+	{ .name = "tps6594x-rtc", },
+};
+
+static struct tps6594x *tps;
+
+static void tps6594x_power_off(void)
+{
+	regmap_write(tps->regmap, TPS6594X_FSM_NSLEEP_TRIGGERS, 0x3);
+	regmap_write(tps->regmap, TPS6594X_INT_STARTUP, 0xff);
+	regmap_write(tps->regmap, TPS6594X_INT_MISC, 0xff);
+	regmap_write(tps->regmap, TPS6594X_CONFIG_1, 0xc0);
+	regmap_write(tps->regmap, TPS6594X_FSM_I2C_TRIGGERS, 0x1);
+}
+
+static int tps6594x_probe(struct i2c_client *client,
+			const struct i2c_device_id *ids)
+{
+	struct tps6594x *tps6594;
+	int ret;
+	unsigned int otpid;
+	struct device_node *node = client->dev.of_node;
+
+	tps6594 = devm_kzalloc(&client->dev, sizeof(*tps6594), GFP_KERNEL);
+	if (!tps6594)
+		return -ENOMEM;
+
+	tps6594->dev = &client->dev;
+
+	tps6594->regmap = devm_regmap_init_i2c(client, &tps6594x_regmap_config);
+	if (IS_ERR(tps6594->regmap)) {
+		ret = PTR_ERR(tps6594->regmap);
+		dev_err(tps6594->dev,
+			"Failed to initialize register map: %d\n", ret);
+		return ret;
+	}
+
+	ret = regmap_read(tps6594->regmap, TPS6594X_REG_DEV_REV, &otpid);
+	if (ret) {
+		dev_err(tps6594->dev, "Failed to read OTP ID\n");
+		return ret;
+	}
+
+	tps6594->rev = otpid;
+
+	i2c_set_clientdata(client, tps6594);
+
+	ret = mfd_add_devices(tps6594->dev, PLATFORM_DEVID_AUTO, tps6594x_cells,
+			      ARRAY_SIZE(tps6594x_cells), NULL, 0, NULL);
+
+	tps = tps6594;
+	if (of_property_read_bool(node, "ti,system-power-controller"))
+		pm_power_off = tps6594x_power_off;
+
+	return ret;
+}
+
+static const struct of_device_id of_tps6594x_match_table[] = {
+	{ .compatible = "ti,tps6594x", },
+	{}
+};
+MODULE_DEVICE_TABLE(of, of_tps6594x_match_table);
+
+static const struct i2c_device_id tps6594x_id_table[] = {
+	{ "tps6594x", 0 },
+	{ },
+};
+MODULE_DEVICE_TABLE(i2c, tps6594x_id_table);
+
+static struct i2c_driver tps6594x_driver = {
+	.driver	= {
+		.name	= "tps6594x",
+		.of_match_table = of_tps6594x_match_table,
+	},
+	.probe		= tps6594x_probe,
+	.id_table	= tps6594x_id_table,
+};
+module_i2c_driver(tps6594x_driver);
+
+MODULE_AUTHOR("J Keerthy <j-keerthy@ti.com>");
+MODULE_DESCRIPTION("TPS6594X chip family Multi-Function Device driver");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/mfd/tps6594x.h b/include/linux/mfd/tps6594x.h
new file mode 100644
index 000000000000..41349f96f013
--- /dev/null
+++ b/include/linux/mfd/tps6594x.h
@@ -0,0 +1,66 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * tps6594x.h  --  TI TPS6594x
+ *
+ * Copyright (C) 2016 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#ifndef __LINUX_MFD_TPS6594X_H
+#define __LINUX_MFD_TPS6594X_H
+
+#include <linux/bits.h>
+
+/* TPS6594x chip id list */
+#define TPS6594X			0x00
+
+/* All register addresses */
+#define TPS6594X_REG_DEV_REV			0x01
+#define TPS6594X_INT_STARTUP			0x65
+#define TPS6594X_INT_MISC			0x66
+#define TPS6594X_CONFIG_1			0x7d
+#define TPS6594X_FSM_I2C_TRIGGERS		0x85
+#define TPS6594X_FSM_NSLEEP_TRIGGERS		0x86
+
+#define TPS6594X_RTC_SECONDS			0xb5
+#define TPS6594X_RTC_MINUTES			0xb6
+#define TPS6594X_RTC_HOURS			0xb7
+#define TPS6594X_RTC_DAYS			0xb8
+#define TPS6594X_RTC_MONTHS			0xb9
+#define TPS6594X_RTC_YEARS			0xba
+#define TPS6594X_RTC_WEEKS			0xbb
+#define TPS6594X_ALARM_SECONDS			0xbc
+#define TPS6594X_ALARM_MINUTES			0xbd
+#define TPS6594X_ALARM_HOURS			0xbe
+#define TPS6594X_ALARM_DAYS			0xbf
+#define TPS6594X_ALARM_MONTHS			0xc0
+#define TPS6594X_ALARM_YEARS			0xc1
+#define TPS6594X_RTC_CTRL_1			0xc2
+#define TPS6594X_RTC_CTRL_2			0xc3
+#define TPS6594X_RTC_STATUS			0xc4
+#define TPS6594X_RTC_INTERRUPTS			0xc5
+#define TPS6594X_REG_MAX			0xd0
+
+/* Register field definitions */
+#define TPS6594X_DEV_REV_DEV_ID			0xff
+
+#define TPS6594X_RTC_CTRL_REG_GET_TIME		BIT(6)
+#define TPS6594X_RTC_CTRL_REG_STOP_RTC		BIT(0)
+#define TPS6594X_RTC_INTERRUPTS_REG_IT_ALARM	BIT(3)
+
+#define TPS6594X_RTC_STATUS_RUN			BIT(1)
+
+/**
+ * struct tps6594x - state holder for the tps6594x driver
+ * @dev: struct device pointer for MFD device
+ * @rev: revision of the tps6594x
+ * @lock: lock guarding the data structure
+ * @regmap: register map of the tps6594x PMIC
+ *
+ * Device data may be used to access the TPS6594X chip
+ */
+struct tps6594x {
+	struct device *dev;
+	u8 rev;
+	struct regmap *regmap;
+};
+#endif /* __LINUX_MFD_TPS6594X_H */
-- 
2.36.1


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

* [PATCH 3/4] rtc: rtc-tps6594x: Add support for TPS6594X PMIC RTC
  2022-08-05  6:43 [PATCH 0/4] mfd: add tps6594x support for j7200 platform Matt Ranostay
  2022-08-05  6:43 ` [PATCH 1/4] Documentation: tps6594x: Add DT bindings for the TPS6594x PMIC Matt Ranostay
  2022-08-05  6:43 ` [PATCH 2/4] MFD: TPS6594x: Add new mfd device for " Matt Ranostay
@ 2022-08-05  6:43 ` Matt Ranostay
  2022-08-05  6:43 ` [PATCH 4/4] arm64: dts: ti: k3-j7200-common-proc-board: Add TPS6594x PMIC node Matt Ranostay
  3 siblings, 0 replies; 9+ messages in thread
From: Matt Ranostay @ 2022-08-05  6:43 UTC (permalink / raw)
  To: lee, nm
  Cc: linux-rtc, linux-kernel, linux-arm-kernel, devicetree, Keerthy,
	Matt Ranostay

From: Keerthy <j-keerthy@ti.com>

Add support for TPS6594X PMIC RTC. However, currently only get/set of
time + date functionality is supported..

Signed-off-by: Keerthy <j-keerthy@ti.com>
Signed-off-by: Matt Ranostay <mranostay@ti.com>
---
 drivers/rtc/Kconfig        |  10 ++
 drivers/rtc/Makefile       |   1 +
 drivers/rtc/rtc-tps6594x.c | 181 +++++++++++++++++++++++++++++++++++++
 3 files changed, 192 insertions(+)
 create mode 100644 drivers/rtc/rtc-tps6594x.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index b8de25118ad0..df8e78eed5fb 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -593,6 +593,16 @@ config RTC_DRV_TPS65910
 	  This driver can also be built as a module. If so, the module
 	  will be called rtc-tps65910.
 
+config RTC_DRV_TPS6594X
+	tristate "TI TPS6594X RTC driver"
+	depends on MFD_TPS6594X
+	help
+	  If you say yes here you get support for the RTC of TI TPS6594X series PMIC
+	  chips.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called rtc-tps6594x.
+
 config RTC_DRV_RC5T583
 	tristate "RICOH 5T583 RTC driver"
 	depends on MFD_RC5T583
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index aab22bc63432..d854e162275a 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -177,6 +177,7 @@ obj-$(CONFIG_RTC_DRV_TEST)	+= rtc-test.o
 obj-$(CONFIG_RTC_DRV_TI_K3)	+= rtc-ti-k3.o
 obj-$(CONFIG_RTC_DRV_TPS6586X)	+= rtc-tps6586x.o
 obj-$(CONFIG_RTC_DRV_TPS65910)	+= rtc-tps65910.o
+obj-$(CONFIG_RTC_DRV_TPS6594X)	+= rtc-tps6594x.o
 obj-$(CONFIG_RTC_DRV_TWL4030)	+= rtc-twl.o
 obj-$(CONFIG_RTC_DRV_V3020)	+= rtc-v3020.o
 obj-$(CONFIG_RTC_DRV_VT8500)	+= rtc-vt8500.o
diff --git a/drivers/rtc/rtc-tps6594x.c b/drivers/rtc/rtc-tps6594x.c
new file mode 100644
index 000000000000..e9f904d0a769
--- /dev/null
+++ b/drivers/rtc/rtc-tps6594x.c
@@ -0,0 +1,181 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * rtc-tps6594x.c -- TPS6594x Real Time Clock driver.
+ *
+ * Copyright (C) 2022 Texas Instruments Incorporated - https://www.ti.com
+ *
+ * TODO: alarm support
+ */
+
+#include <linux/bcd.h>
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/mfd/tps6594x.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/rtc.h>
+#include <linux/types.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+
+struct tps6594x_rtc {
+	struct rtc_device	*rtc;
+	struct device		*dev;
+};
+
+#define TPS6594X_NUM_TIME_REGS	(TPS6594X_RTC_YEARS - TPS6594X_RTC_SECONDS + 1)
+
+static int tps6594x_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+	unsigned char rtc_data[TPS6594X_NUM_TIME_REGS];
+	struct tps6594x *tps6594x = dev_get_drvdata(dev->parent);
+	int ret;
+
+	/* Reset TPS6594X_RTC_CTRL_REG_GET_TIME bit to zero, required for latch */
+	ret = regmap_update_bits(tps6594x->regmap, TPS6594X_RTC_CTRL_1,
+		TPS6594X_RTC_CTRL_REG_GET_TIME, 0);
+	if (ret < 0) {
+		dev_err(dev, "RTC CTRL reg update failed, err: %d\n", ret);
+		return ret;
+	}
+
+	/* Copy RTC counting registers to static registers or latches */
+	ret = regmap_update_bits(tps6594x->regmap, TPS6594X_RTC_CTRL_1,
+		TPS6594X_RTC_CTRL_REG_GET_TIME, TPS6594X_RTC_CTRL_REG_GET_TIME);
+	if (ret < 0) {
+		dev_err(dev, "RTC CTRL reg update failed, err: %d\n", ret);
+		return ret;
+	}
+
+	ret = regmap_bulk_read(tps6594x->regmap, TPS6594X_RTC_SECONDS,
+			rtc_data, TPS6594X_NUM_TIME_REGS);
+	if (ret < 0) {
+		dev_err(dev, "RTC_SECONDS reg read failed, err = %d\n", ret);
+		return ret;
+	}
+
+	tm->tm_sec = bcd2bin(rtc_data[0]);
+	tm->tm_min = bcd2bin(rtc_data[1]);
+	tm->tm_hour = bcd2bin(rtc_data[2]);
+	tm->tm_mday = bcd2bin(rtc_data[3]);
+	tm->tm_mon = bcd2bin(rtc_data[4]) - 1;
+	tm->tm_year = bcd2bin(rtc_data[5]) + 100;
+
+	return ret;
+}
+
+static int tps6594x_rtc_set_time(struct device *dev, struct rtc_time *tm)
+{
+	unsigned char rtc_data[TPS6594X_NUM_TIME_REGS];
+	struct tps6594x *tps6594x = dev_get_drvdata(dev->parent);
+	int ret, retries = 5;
+	unsigned int val;
+
+	rtc_data[0] = bin2bcd(tm->tm_sec);
+	rtc_data[1] = bin2bcd(tm->tm_min);
+	rtc_data[2] = bin2bcd(tm->tm_hour);
+	rtc_data[3] = bin2bcd(tm->tm_mday);
+	rtc_data[4] = bin2bcd(tm->tm_mon + 1);
+	rtc_data[5] = bin2bcd(tm->tm_year - 100);
+
+	/* Stop RTC while updating the RTC time registers */
+	ret = regmap_update_bits(tps6594x->regmap, TPS6594X_RTC_CTRL_1,
+				 TPS6594X_RTC_CTRL_REG_STOP_RTC, 0);
+	if (ret < 0) {
+		dev_err(dev, "RTC stop failed, err = %d\n", ret);
+		return ret;
+	}
+
+	/* Waiting till RTC isn't running */
+	do {
+		ret = regmap_read(tps6594x->regmap, TPS6594X_RTC_STATUS, &val);
+		if (ret < 0) {
+			dev_err(dev, "RTC_STATUS reg read failed, err = %d\n", ret);
+			return ret;
+		}
+		msleep(20);
+	} while (--retries && (val & TPS6594X_RTC_STATUS_RUN));
+
+	if (!retries) {
+		dev_err(dev, "RTC_STATUS is still RUNNING\n");
+		return -ETIMEDOUT;
+	}
+
+	ret = regmap_bulk_write(tps6594x->regmap, TPS6594X_RTC_SECONDS,
+		rtc_data, TPS6594X_NUM_TIME_REGS);
+	if (ret < 0) {
+		dev_err(dev, "RTC_SECONDS reg write failed, err = %d\n", ret);
+		return ret;
+	}
+
+	/* Start back RTC */
+	ret = regmap_update_bits(tps6594x->regmap, TPS6594X_RTC_CTRL_1,
+				 TPS6594X_RTC_CTRL_REG_STOP_RTC,
+				 TPS6594X_RTC_CTRL_REG_STOP_RTC);
+	if (ret < 0)
+		dev_err(dev, "RTC start failed, err = %d\n", ret);
+
+	return ret;
+}
+
+static const struct rtc_class_ops tps6594x_rtc_ops = {
+	.read_time	= tps6594x_rtc_read_time,
+	.set_time	= tps6594x_rtc_set_time,
+};
+
+static int tps6594x_rtc_probe(struct platform_device *pdev)
+{
+	struct tps6594x *tps6594x = dev_get_drvdata(pdev->dev.parent);
+	struct tps6594x_rtc *tps6594x_rtc = NULL;
+	int ret;
+
+	tps6594x_rtc = devm_kzalloc(&pdev->dev, sizeof(struct tps6594x_rtc), GFP_KERNEL);
+	if (!tps6594x_rtc)
+		return -ENOMEM;
+
+	tps6594x_rtc->dev = &pdev->dev;
+	platform_set_drvdata(pdev, tps6594x_rtc);
+
+	/* Start RTC */
+	ret = regmap_update_bits(tps6594x->regmap, TPS6594X_RTC_CTRL_1,
+				 TPS6594X_RTC_CTRL_REG_STOP_RTC,
+				 TPS6594X_RTC_CTRL_REG_STOP_RTC);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "RTC_CTRL write failed, err = %d\n", ret);
+		return ret;
+	}
+
+	tps6594x_rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
+				&tps6594x_rtc_ops, THIS_MODULE);
+	if (IS_ERR(tps6594x_rtc->rtc)) {
+		ret = PTR_ERR(tps6594x_rtc->rtc);
+		dev_err(&pdev->dev, "RTC register failed, err = %d\n", ret);
+		return ret;
+	}
+
+	return 0;
+}
+
+#ifdef CONFIG_OF
+static const struct of_device_id of_tps6594x_rtc_match[] = {
+	{ .compatible = "ti,tps6594x-rtc", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, of_tps6594x_rtc_match);
+#endif
+
+static struct platform_driver tps6594x_rtc_driver = {
+	.probe		= tps6594x_rtc_probe,
+	.driver		= {
+		.name	= "tps6594x-rtc",
+		.of_match_table = of_match_ptr(of_tps6594x_rtc_match),
+	},
+};
+
+module_platform_driver(tps6594x_rtc_driver);
+
+MODULE_ALIAS("platform:tps6594x_rtc");
+MODULE_DESCRIPTION("TI TPS6594x series RTC driver");
+MODULE_AUTHOR("Keerthy J <j-keerthy@ti.com>");
+MODULE_LICENSE("GPL");
-- 
2.36.1


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

* [PATCH 4/4] arm64: dts: ti: k3-j7200-common-proc-board: Add TPS6594x PMIC node
  2022-08-05  6:43 [PATCH 0/4] mfd: add tps6594x support for j7200 platform Matt Ranostay
                   ` (2 preceding siblings ...)
  2022-08-05  6:43 ` [PATCH 3/4] rtc: rtc-tps6594x: Add support for TPS6594X PMIC RTC Matt Ranostay
@ 2022-08-05  6:43 ` Matt Ranostay
  3 siblings, 0 replies; 9+ messages in thread
From: Matt Ranostay @ 2022-08-05  6:43 UTC (permalink / raw)
  To: lee, nm; +Cc: linux-rtc, linux-kernel, linux-arm-kernel, devicetree, Keerthy

From: Keerthy <j-keerthy@ti.com>

Add TPS6594x PMIC + RTC definition for J7200 common processor board
device tree.

Signed-off-by: Keerthy <j-keerthy@ti.com>
---
 .../boot/dts/ti/k3-j7200-common-proc-board.dts   | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/arch/arm64/boot/dts/ti/k3-j7200-common-proc-board.dts b/arch/arm64/boot/dts/ti/k3-j7200-common-proc-board.dts
index 121975dc8239..6deab4f9a04b 100644
--- a/arch/arm64/boot/dts/ti/k3-j7200-common-proc-board.dts
+++ b/arch/arm64/boot/dts/ti/k3-j7200-common-proc-board.dts
@@ -353,3 +353,19 @@ &pcie1_ep {
 	num-lanes = <2>;
 	status = "disabled";
 };
+
+&wkup_i2c0 {
+	status = "okay";
+};
+
+&wkup_i2c0 {
+	tps6594x: tps6594x@48 {
+		compatible = "ti,tps6594x";
+		reg = <0x48>;
+		ti,system-power-controller;
+
+		rtc {
+			compatible = "ti,tps6594x-rtc";
+		};
+	};
+};
-- 
2.36.1


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

* Re: [PATCH 1/4] Documentation: tps6594x: Add DT bindings for the TPS6594x PMIC
  2022-08-05  6:43 ` [PATCH 1/4] Documentation: tps6594x: Add DT bindings for the TPS6594x PMIC Matt Ranostay
@ 2022-08-05 14:14   ` Rob Herring
  0 siblings, 0 replies; 9+ messages in thread
From: Rob Herring @ 2022-08-05 14:14 UTC (permalink / raw)
  To: Matt Ranostay
  Cc: devicetree, linux-kernel, linux-arm-kernel, lee, nm, linux-rtc

On Thu, 04 Aug 2022 23:43:49 -0700, Matt Ranostay wrote:
> Signed-off-by: Matt Ranostay <mranostay@ti.com>
> ---
>  .../devicetree/bindings/mfd/ti,tps6594x.yaml  | 53 +++++++++++++++++++
>  1 file changed, 53 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/mfd/ti,tps6594x.yaml
> 

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check'
on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:

dtschema/dtc warnings/errors:
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/mfd/ti,tps6594x.yaml: properties:ti,system-power-controller: 'oneOf' conditional failed, one must be fixed:
	'type' is a required property
		hint: A vendor boolean property can use "type: boolean"
	/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/mfd/ti,tps6594x.yaml: properties:ti,system-power-controller: 'oneOf' conditional failed, one must be fixed:
		'enum' is a required property
		'const' is a required property
		hint: A vendor string property with exact values has an implicit type
		from schema $id: http://devicetree.org/meta-schemas/vendor-props.yaml#
	/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/mfd/ti,tps6594x.yaml: properties:ti,system-power-controller: 'oneOf' conditional failed, one must be fixed:
		'$ref' is a required property
		'allOf' is a required property
		hint: A vendor property needs a $ref to types.yaml
		from schema $id: http://devicetree.org/meta-schemas/vendor-props.yaml#
	hint: Vendor specific properties must have a type and description unless they have a defined, common suffix.
	from schema $id: http://devicetree.org/meta-schemas/vendor-props.yaml#
./Documentation/devicetree/bindings/mfd/ti,tps6594x.yaml: $id: relative path/filename doesn't match actual path or filename
	expected: http://devicetree.org/schemas/mfd/ti,tps6594x.yaml#
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/mfd/ti,tps6594x.yaml: ignoring, error in schema: properties: ti,system-power-controller
Documentation/devicetree/bindings/mfd/ti,tps6594x.example.dtb:0:0: /example-0/i2c0/pmic@48: failed to match any schema with compatible: ['ti,tps6594x']
Documentation/devicetree/bindings/mfd/ti,tps6594x.example.dtb:0:0: /example-0/i2c0/pmic@48/rtc: failed to match any schema with compatible: ['ti,tps6594x-rtc']

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/patch/

This check can fail if there are any dependencies. The base for a patch
series is generally the most recent rc1.

If you already ran 'make dt_binding_check' and didn't see the above
error(s), then make sure 'yamllint' is installed and dt-schema is up to
date:

pip3 install dtschema --upgrade

Please check and re-submit.


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

* Re: [PATCH 2/4] MFD: TPS6594x: Add new mfd device for TPS6594x PMIC
  2022-08-05  6:43 ` [PATCH 2/4] MFD: TPS6594x: Add new mfd device for " Matt Ranostay
@ 2022-08-10 11:27   ` Lee Jones
  2022-08-11  6:33     ` Matt Ranostay
  0 siblings, 1 reply; 9+ messages in thread
From: Lee Jones @ 2022-08-10 11:27 UTC (permalink / raw)
  To: Matt Ranostay
  Cc: nm, linux-rtc, linux-kernel, linux-arm-kernel, devicetree, Keerthy

On Thu, 04 Aug 2022, Matt Ranostay wrote:

> From: Keerthy <j-keerthy@ti.com>
> 
> The TPS6594x chip is a PMIC, and contains the following components:
> 
> - Regulators
> - GPIO controller
> - RTC
> 
> However initially only RTC is supported.
> 
> Signed-off-by: Keerthy <j-keerthy@ti.com>
> Signed-off-by: Matt Ranostay <mranostay@ti.com>
> ---
>  drivers/mfd/Kconfig          |  14 +++++
>  drivers/mfd/Makefile         |   1 +
>  drivers/mfd/tps6594x.c       | 106 +++++++++++++++++++++++++++++++++++
>  include/linux/mfd/tps6594x.h |  66 ++++++++++++++++++++++
>  4 files changed, 187 insertions(+)
>  create mode 100644 drivers/mfd/tps6594x.c
>  create mode 100644 include/linux/mfd/tps6594x.h
> 
> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> index abb58ab1a1a4..cfb5b3d66b76 100644
> --- a/drivers/mfd/Kconfig
> +++ b/drivers/mfd/Kconfig
> @@ -1547,6 +1547,20 @@ config MFD_TI_LP873X
>  	  This driver can also be built as a module. If so, the module
>  	  will be called lp873x.
>  
> +config MFD_TPS6594X
> +	tristate "TI TPS6594X Power Management IC"
> +	depends on I2C
> +	select MFD_CORE
> +	select REGMAP_I2C
> +	help
> +	  If you say yes here then you get support for the TPS6594X series of
> +	  Power Management Integrated Circuits (PMIC).
> +	  These include voltage regulators, RTS, configurable
> +	  General Purpose Outputs (GPO) that are used in portable devices.
> +
> +	  This driver can also be built as a module. If so, the module
> +	  will be called tps7694x.
> +
>  config MFD_TI_LP87565
>  	tristate "TI LP87565 Power Management IC"
>  	depends on I2C && OF
> diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
> index 858cacf659d6..7ff6a8a57d55 100644
> --- a/drivers/mfd/Makefile
> +++ b/drivers/mfd/Makefile
> @@ -105,6 +105,7 @@ obj-$(CONFIG_MFD_TPS65910)	+= tps65910.o
>  obj-$(CONFIG_MFD_TPS65912)	+= tps65912-core.o
>  obj-$(CONFIG_MFD_TPS65912_I2C)	+= tps65912-i2c.o
>  obj-$(CONFIG_MFD_TPS65912_SPI)  += tps65912-spi.o
> +obj-$(CONFIG_MFD_TPS6594X)	+= tps6594x.o
>  obj-$(CONFIG_MENELAUS)		+= menelaus.o
>  
>  obj-$(CONFIG_TWL4030_CORE)	+= twl-core.o twl4030-irq.o twl6030-irq.o
> diff --git a/drivers/mfd/tps6594x.c b/drivers/mfd/tps6594x.c
> new file mode 100644
> index 000000000000..519162cc1fbe
> --- /dev/null
> +++ b/drivers/mfd/tps6594x.c
> @@ -0,0 +1,106 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * tps6594x.c  --  TI TPS6594x chip family multi-function driver

No filenames in comments please.

Also, there are too many spaces around the '--'.

It's not a "multi-function driver" it's a PMIC Core driver.

> + * Copyright (C) 2022 Texas Instruments Incorporated - https://www.ti.com/
> + *
> + * Author: Keerthy <j-keerthy@ti.com>
> + */
> +
> +#include <linux/interrupt.h>
> +#include <linux/mfd/core.h>
> +#include <linux/module.h>
> +#include <linux/of_device.h>
> +#include <linux/i2c.h>
> +#include <linux/regmap.h>

Alphabetical.

> +#include <linux/mfd/tps6594x.h>
> +
> +static const struct regmap_config tps6594x_regmap_config = {
> +	.reg_bits = 8,
> +	.val_bits = 8,
> +	.max_register = TPS6594X_REG_MAX,
> +};
> +
> +static const struct mfd_cell tps6594x_cells[] = {
> +	{ .name = "tps6594x-rtc", },
> +};

Where are the rest of the devices?

This is not an MFD with only one device.

> +static struct tps6594x *tps;
> +
> +static void tps6594x_power_off(void)
> +{
> +	regmap_write(tps->regmap, TPS6594X_FSM_NSLEEP_TRIGGERS, 0x3);
> +	regmap_write(tps->regmap, TPS6594X_INT_STARTUP, 0xff);
> +	regmap_write(tps->regmap, TPS6594X_INT_MISC, 0xff);
> +	regmap_write(tps->regmap, TPS6594X_CONFIG_1, 0xc0);
> +	regmap_write(tps->regmap, TPS6594X_FSM_I2C_TRIGGERS, 0x1);

No magic numbers please.  Define all of those values.

> +}
> +
> +static int tps6594x_probe(struct i2c_client *client,
> +			const struct i2c_device_id *ids)
> +{
> +	struct tps6594x *tps6594;

*ddata is preferred.

> +	int ret;
> +	unsigned int otpid;
> +	struct device_node *node = client->dev.of_node;

Re-order these - usually 'structs' go first, then ints.

> +	tps6594 = devm_kzalloc(&client->dev, sizeof(*tps6594), GFP_KERNEL);
> +	if (!tps6594)
> +		return -ENOMEM;
> +
> +	tps6594->dev = &client->dev;
> +
> +	tps6594->regmap = devm_regmap_init_i2c(client, &tps6594x_regmap_config);
> +	if (IS_ERR(tps6594->regmap)) {
> +		ret = PTR_ERR(tps6594->regmap);
> +		dev_err(tps6594->dev,
> +			"Failed to initialize register map: %d\n", ret);
> +		return ret;
> +	}
> +
> +	ret = regmap_read(tps6594->regmap, TPS6594X_REG_DEV_REV, &otpid);
> +	if (ret) {
> +		dev_err(tps6594->dev, "Failed to read OTP ID\n");
> +		return ret;
> +	}
> +
> +	tps6594->rev = otpid;
> +
> +	i2c_set_clientdata(client, tps6594);
> +
> +	ret = mfd_add_devices(tps6594->dev, PLATFORM_DEVID_AUTO, tps6594x_cells,
> +			      ARRAY_SIZE(tps6594x_cells), NULL, 0, NULL);
> +
> +	tps = tps6594;
> +	if (of_property_read_bool(node, "ti,system-power-controller"))
> +		pm_power_off = tps6594x_power_off;

You setting this up even if mfd_add_devices() fails?

Seems wrong.

> +	return ret;
> +}
> +
> +static const struct of_device_id of_tps6594x_match_table[] = {
> +	{ .compatible = "ti,tps6594x", },
> +	{}
> +};
> +MODULE_DEVICE_TABLE(of, of_tps6594x_match_table);
> +
> +static const struct i2c_device_id tps6594x_id_table[] = {
> +	{ "tps6594x", 0 },
> +	{ },
> +};
> +MODULE_DEVICE_TABLE(i2c, tps6594x_id_table);

Remove this and use .probe_new instead please.

> +static struct i2c_driver tps6594x_driver = {
> +	.driver	= {
> +		.name	= "tps6594x",
> +		.of_match_table = of_tps6594x_match_table,
> +	},
> +	.probe		= tps6594x_probe,
> +	.id_table	= tps6594x_id_table,
> +};
> +module_i2c_driver(tps6594x_driver);
> +
> +MODULE_AUTHOR("J Keerthy <j-keerthy@ti.com>");
> +MODULE_DESCRIPTION("TPS6594X chip family Multi-Function Device driver");

Not an MFD.

> +MODULE_LICENSE("GPL");
> diff --git a/include/linux/mfd/tps6594x.h b/include/linux/mfd/tps6594x.h
> new file mode 100644
> index 000000000000..41349f96f013
> --- /dev/null
> +++ b/include/linux/mfd/tps6594x.h
> @@ -0,0 +1,66 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + * tps6594x.h  --  TI TPS6594x

No filenames.

> + * Copyright (C) 2016 Texas Instruments Incorporated - https://www.ti.com/

2016?

> + */
> +
> +#ifndef __LINUX_MFD_TPS6594X_H
> +#define __LINUX_MFD_TPS6594X_H

Any reason go keep the LINUX part?

> +#include <linux/bits.h>
> +
> +/* TPS6594x chip id list */

"ID"

> +#define TPS6594X			0x00
> +
> +/* All register addresses */
> +#define TPS6594X_REG_DEV_REV			0x01
> +#define TPS6594X_INT_STARTUP			0x65
> +#define TPS6594X_INT_MISC			0x66
> +#define TPS6594X_CONFIG_1			0x7d
> +#define TPS6594X_FSM_I2C_TRIGGERS		0x85
> +#define TPS6594X_FSM_NSLEEP_TRIGGERS		0x86
> +
> +#define TPS6594X_RTC_SECONDS			0xb5
> +#define TPS6594X_RTC_MINUTES			0xb6
> +#define TPS6594X_RTC_HOURS			0xb7
> +#define TPS6594X_RTC_DAYS			0xb8
> +#define TPS6594X_RTC_MONTHS			0xb9
> +#define TPS6594X_RTC_YEARS			0xba
> +#define TPS6594X_RTC_WEEKS			0xbb
> +#define TPS6594X_ALARM_SECONDS			0xbc
> +#define TPS6594X_ALARM_MINUTES			0xbd
> +#define TPS6594X_ALARM_HOURS			0xbe
> +#define TPS6594X_ALARM_DAYS			0xbf
> +#define TPS6594X_ALARM_MONTHS			0xc0
> +#define TPS6594X_ALARM_YEARS			0xc1
> +#define TPS6594X_RTC_CTRL_1			0xc2
> +#define TPS6594X_RTC_CTRL_2			0xc3
> +#define TPS6594X_RTC_STATUS			0xc4
> +#define TPS6594X_RTC_INTERRUPTS			0xc5
> +#define TPS6594X_REG_MAX			0xd0
> +
> +/* Register field definitions */
> +#define TPS6594X_DEV_REV_DEV_ID			0xff
> +
> +#define TPS6594X_RTC_CTRL_REG_GET_TIME		BIT(6)
> +#define TPS6594X_RTC_CTRL_REG_STOP_RTC		BIT(0)
> +#define TPS6594X_RTC_INTERRUPTS_REG_IT_ALARM	BIT(3)
> +
> +#define TPS6594X_RTC_STATUS_RUN			BIT(1)
> +
> +/**
> + * struct tps6594x - state holder for the tps6594x driver
> + * @dev: struct device pointer for MFD device
> + * @rev: revision of the tps6594x
> + * @lock: lock guarding the data structure
> + * @regmap: register map of the tps6594x PMIC
> + *
> + * Device data may be used to access the TPS6594X chip
> + */
> +struct tps6594x {
> +	struct device *dev;
> +	u8 rev;
> +	struct regmap *regmap;
> +};

Please test compile with W=1 enabled and fix the issues.

> +#endif /* __LINUX_MFD_TPS6594X_H */

-- 
Lee Jones [李琼斯]

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

* Re: [PATCH 2/4] MFD: TPS6594x: Add new mfd device for TPS6594x PMIC
  2022-08-10 11:27   ` Lee Jones
@ 2022-08-11  6:33     ` Matt Ranostay
  2022-08-11  7:04       ` Lee Jones
  0 siblings, 1 reply; 9+ messages in thread
From: Matt Ranostay @ 2022-08-11  6:33 UTC (permalink / raw)
  To: Lee Jones
  Cc: nm, linux-rtc, linux-kernel, linux-arm-kernel, devicetree, Keerthy

On Wed, Aug 10, 2022 at 12:27:25PM +0100, Lee Jones wrote:
> On Thu, 04 Aug 2022, Matt Ranostay wrote:
> 
> > From: Keerthy <j-keerthy@ti.com>
> > 
> > The TPS6594x chip is a PMIC, and contains the following components:
> > 
> > - Regulators
> > - GPIO controller
> > - RTC
> > 
> > However initially only RTC is supported.
> > 
> > Signed-off-by: Keerthy <j-keerthy@ti.com>
> > Signed-off-by: Matt Ranostay <mranostay@ti.com>
> > ---
> >  drivers/mfd/Kconfig          |  14 +++++
> >  drivers/mfd/Makefile         |   1 +
> >  drivers/mfd/tps6594x.c       | 106 +++++++++++++++++++++++++++++++++++
> >  include/linux/mfd/tps6594x.h |  66 ++++++++++++++++++++++
> >  4 files changed, 187 insertions(+)
> >  create mode 100644 drivers/mfd/tps6594x.c
> >  create mode 100644 include/linux/mfd/tps6594x.h
> > 
> > diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> > index abb58ab1a1a4..cfb5b3d66b76 100644
> > --- a/drivers/mfd/Kconfig
> > +++ b/drivers/mfd/Kconfig
> > @@ -1547,6 +1547,20 @@ config MFD_TI_LP873X
> >  	  This driver can also be built as a module. If so, the module
> >  	  will be called lp873x.
> >  
> > +config MFD_TPS6594X
> > +	tristate "TI TPS6594X Power Management IC"
> > +	depends on I2C
> > +	select MFD_CORE
> > +	select REGMAP_I2C
> > +	help
> > +	  If you say yes here then you get support for the TPS6594X series of
> > +	  Power Management Integrated Circuits (PMIC).
> > +	  These include voltage regulators, RTS, configurable
> > +	  General Purpose Outputs (GPO) that are used in portable devices.
> > +
> > +	  This driver can also be built as a module. If so, the module
> > +	  will be called tps7694x.
> > +
> >  config MFD_TI_LP87565
> >  	tristate "TI LP87565 Power Management IC"
> >  	depends on I2C && OF
> > diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
> > index 858cacf659d6..7ff6a8a57d55 100644
> > --- a/drivers/mfd/Makefile
> > +++ b/drivers/mfd/Makefile
> > @@ -105,6 +105,7 @@ obj-$(CONFIG_MFD_TPS65910)	+= tps65910.o
> >  obj-$(CONFIG_MFD_TPS65912)	+= tps65912-core.o
> >  obj-$(CONFIG_MFD_TPS65912_I2C)	+= tps65912-i2c.o
> >  obj-$(CONFIG_MFD_TPS65912_SPI)  += tps65912-spi.o
> > +obj-$(CONFIG_MFD_TPS6594X)	+= tps6594x.o
> >  obj-$(CONFIG_MENELAUS)		+= menelaus.o
> >  
> >  obj-$(CONFIG_TWL4030_CORE)	+= twl-core.o twl4030-irq.o twl6030-irq.o
> > diff --git a/drivers/mfd/tps6594x.c b/drivers/mfd/tps6594x.c
> > new file mode 100644
> > index 000000000000..519162cc1fbe
> > --- /dev/null
> > +++ b/drivers/mfd/tps6594x.c
> > @@ -0,0 +1,106 @@
> > +// SPDX-License-Identifier: GPL-2.0-or-later
> > +/*
> > + * tps6594x.c  --  TI TPS6594x chip family multi-function driver
> 
> No filenames in comments please.
> 
> Also, there are too many spaces around the '--'.
> 
> It's not a "multi-function driver" it's a PMIC Core driver.
>

Noted. Will change to PMIC core driver to be more concise.

> > + * Copyright (C) 2022 Texas Instruments Incorporated - https://www.ti.com/
> > + *
> > + * Author: Keerthy <j-keerthy@ti.com>
> > + */
> > +
> > +#include <linux/interrupt.h>
> > +#include <linux/mfd/core.h>
> > +#include <linux/module.h>
> > +#include <linux/of_device.h>
> > +#include <linux/i2c.h>
> > +#include <linux/regmap.h>
> 
> Alphabetical.
> 
> > +#include <linux/mfd/tps6594x.h>
> > +
> > +static const struct regmap_config tps6594x_regmap_config = {
> > +	.reg_bits = 8,
> > +	.val_bits = 8,
> > +	.max_register = TPS6594X_REG_MAX,
> > +};
> > +
> > +static const struct mfd_cell tps6594x_cells[] = {
> > +	{ .name = "tps6594x-rtc", },
> > +};
> 
> Where are the rest of the devices?
> 
> This is not an MFD with only one device.

There are other devices, however there isn't any drivers currently for them
just the RTC. Should there be placeholders for the gpio, and regulators even
if support currently doesn't exist.

> 
> > +static struct tps6594x *tps;
> > +
> > +static void tps6594x_power_off(void)
> > +{
> > +	regmap_write(tps->regmap, TPS6594X_FSM_NSLEEP_TRIGGERS, 0x3);
> > +	regmap_write(tps->regmap, TPS6594X_INT_STARTUP, 0xff);
> > +	regmap_write(tps->regmap, TPS6594X_INT_MISC, 0xff);
> > +	regmap_write(tps->regmap, TPS6594X_CONFIG_1, 0xc0);
> > +	regmap_write(tps->regmap, TPS6594X_FSM_I2C_TRIGGERS, 0x1);
> 
> No magic numbers please.  Define all of those values.
>

Will add some defines for the bitmasking to make more clear.

> > +}
> > +
> > +static int tps6594x_probe(struct i2c_client *client,
> > +			const struct i2c_device_id *ids)
> > +{
> > +	struct tps6594x *tps6594;
> 
> *ddata is preferred.
> 
> > +	int ret;
> > +	unsigned int otpid;
> > +	struct device_node *node = client->dev.of_node;
> 
> Re-order these - usually 'structs' go first, then ints.
> 
> > +	tps6594 = devm_kzalloc(&client->dev, sizeof(*tps6594), GFP_KERNEL);
> > +	if (!tps6594)
> > +		return -ENOMEM;
> > +
> > +	tps6594->dev = &client->dev;
> > +
> > +	tps6594->regmap = devm_regmap_init_i2c(client, &tps6594x_regmap_config);
> > +	if (IS_ERR(tps6594->regmap)) {
> > +		ret = PTR_ERR(tps6594->regmap);
> > +		dev_err(tps6594->dev,
> > +			"Failed to initialize register map: %d\n", ret);
> > +		return ret;
> > +	}
> > +
> > +	ret = regmap_read(tps6594->regmap, TPS6594X_REG_DEV_REV, &otpid);
> > +	if (ret) {
> > +		dev_err(tps6594->dev, "Failed to read OTP ID\n");
> > +		return ret;
> > +	}
> > +
> > +	tps6594->rev = otpid;
> > +
> > +	i2c_set_clientdata(client, tps6594);
> > +
> > +	ret = mfd_add_devices(tps6594->dev, PLATFORM_DEVID_AUTO, tps6594x_cells,
> > +			      ARRAY_SIZE(tps6594x_cells), NULL, 0, NULL);
> > +
> > +	tps = tps6594;
> > +	if (of_property_read_bool(node, "ti,system-power-controller"))
> > +		pm_power_off = tps6594x_power_off;
> 
> You setting this up even if mfd_add_devices() fails?
> 
> Seems wrong.
> 

Good catch.. yes it shouldn't be setup in that case.

> > +	return ret;
> > +}
> > +
> > +static const struct of_device_id of_tps6594x_match_table[] = {
> > +	{ .compatible = "ti,tps6594x", },
> > +	{}
> > +};
> > +MODULE_DEVICE_TABLE(of, of_tps6594x_match_table);
> > +
> > +static const struct i2c_device_id tps6594x_id_table[] = {
> > +	{ "tps6594x", 0 },
> > +	{ },
> > +};
> > +MODULE_DEVICE_TABLE(i2c, tps6594x_id_table);
> 
> Remove this and use .probe_new instead please.
> 
> > +static struct i2c_driver tps6594x_driver = {
> > +	.driver	= {
> > +		.name	= "tps6594x",
> > +		.of_match_table = of_tps6594x_match_table,
> > +	},
> > +	.probe		= tps6594x_probe,
> > +	.id_table	= tps6594x_id_table,
> > +};
> > +module_i2c_driver(tps6594x_driver);
> > +
> > +MODULE_AUTHOR("J Keerthy <j-keerthy@ti.com>");
> > +MODULE_DESCRIPTION("TPS6594X chip family Multi-Function Device driver");
> 
> Not an MFD.
> 
> > +MODULE_LICENSE("GPL");
> > diff --git a/include/linux/mfd/tps6594x.h b/include/linux/mfd/tps6594x.h
> > new file mode 100644
> > index 000000000000..41349f96f013
> > --- /dev/null
> > +++ b/include/linux/mfd/tps6594x.h
> > @@ -0,0 +1,66 @@
> > +/* SPDX-License-Identifier: GPL-2.0-or-later */
> > +/*
> > + * tps6594x.h  --  TI TPS6594x
> 
> No filenames.
> 

Noted.

> > + * Copyright (C) 2016 Texas Instruments Incorporated - https://www.ti.com/
> 
> 2016?

From internal tree likely, but copyrights should be updated.

> 
> > + */
> > +
> > +#ifndef __LINUX_MFD_TPS6594X_H
> > +#define __LINUX_MFD_TPS6594X_H
> 
> Any reason go keep the LINUX part?
> 

Nope not any real reason.

> > +#include <linux/bits.h>
> > +
> > +/* TPS6594x chip id list */
> 
> "ID"
> 
> > +#define TPS6594X			0x00
> > +
> > +/* All register addresses */
> > +#define TPS6594X_REG_DEV_REV			0x01
> > +#define TPS6594X_INT_STARTUP			0x65
> > +#define TPS6594X_INT_MISC			0x66
> > +#define TPS6594X_CONFIG_1			0x7d
> > +#define TPS6594X_FSM_I2C_TRIGGERS		0x85
> > +#define TPS6594X_FSM_NSLEEP_TRIGGERS		0x86
> > +
> > +#define TPS6594X_RTC_SECONDS			0xb5
> > +#define TPS6594X_RTC_MINUTES			0xb6
> > +#define TPS6594X_RTC_HOURS			0xb7
> > +#define TPS6594X_RTC_DAYS			0xb8
> > +#define TPS6594X_RTC_MONTHS			0xb9
> > +#define TPS6594X_RTC_YEARS			0xba
> > +#define TPS6594X_RTC_WEEKS			0xbb
> > +#define TPS6594X_ALARM_SECONDS			0xbc
> > +#define TPS6594X_ALARM_MINUTES			0xbd
> > +#define TPS6594X_ALARM_HOURS			0xbe
> > +#define TPS6594X_ALARM_DAYS			0xbf
> > +#define TPS6594X_ALARM_MONTHS			0xc0
> > +#define TPS6594X_ALARM_YEARS			0xc1
> > +#define TPS6594X_RTC_CTRL_1			0xc2
> > +#define TPS6594X_RTC_CTRL_2			0xc3
> > +#define TPS6594X_RTC_STATUS			0xc4
> > +#define TPS6594X_RTC_INTERRUPTS			0xc5
> > +#define TPS6594X_REG_MAX			0xd0
> > +
> > +/* Register field definitions */
> > +#define TPS6594X_DEV_REV_DEV_ID			0xff
> > +
> > +#define TPS6594X_RTC_CTRL_REG_GET_TIME		BIT(6)
> > +#define TPS6594X_RTC_CTRL_REG_STOP_RTC		BIT(0)
> > +#define TPS6594X_RTC_INTERRUPTS_REG_IT_ALARM	BIT(3)
> > +
> > +#define TPS6594X_RTC_STATUS_RUN			BIT(1)
> > +
> > +/**
> > + * struct tps6594x - state holder for the tps6594x driver
> > + * @dev: struct device pointer for MFD device
> > + * @rev: revision of the tps6594x
> > + * @lock: lock guarding the data structure
> > + * @regmap: register map of the tps6594x PMIC
> > + *
> > + * Device data may be used to access the TPS6594X chip
> > + */
> > +struct tps6594x {
> > +	struct device *dev;
> > +	u8 rev;
> > +	struct regmap *regmap;
> > +};
> 
> Please test compile with W=1 enabled and fix the issues.
>

Thanks,

Matt

> > +#endif /* __LINUX_MFD_TPS6594X_H */
> 
> -- 
> Lee Jones [李琼斯]

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

* Re: [PATCH 2/4] MFD: TPS6594x: Add new mfd device for TPS6594x PMIC
  2022-08-11  6:33     ` Matt Ranostay
@ 2022-08-11  7:04       ` Lee Jones
  0 siblings, 0 replies; 9+ messages in thread
From: Lee Jones @ 2022-08-11  7:04 UTC (permalink / raw)
  To: Matt Ranostay
  Cc: nm, linux-rtc, linux-kernel, linux-arm-kernel, devicetree, Keerthy

On Wed, 10 Aug 2022, Matt Ranostay wrote:

> On Wed, Aug 10, 2022 at 12:27:25PM +0100, Lee Jones wrote:
> > On Thu, 04 Aug 2022, Matt Ranostay wrote:
> > 
> > > From: Keerthy <j-keerthy@ti.com>
> > > 
> > > The TPS6594x chip is a PMIC, and contains the following components:
> > > 
> > > - Regulators
> > > - GPIO controller
> > > - RTC
> > > 
> > > However initially only RTC is supported.
> > > 
> > > Signed-off-by: Keerthy <j-keerthy@ti.com>
> > > Signed-off-by: Matt Ranostay <mranostay@ti.com>
> > > ---
> > >  drivers/mfd/Kconfig          |  14 +++++
> > >  drivers/mfd/Makefile         |   1 +
> > >  drivers/mfd/tps6594x.c       | 106 +++++++++++++++++++++++++++++++++++
> > >  include/linux/mfd/tps6594x.h |  66 ++++++++++++++++++++++
> > >  4 files changed, 187 insertions(+)
> > >  create mode 100644 drivers/mfd/tps6594x.c
> > >  create mode 100644 include/linux/mfd/tps6594x.h
> > > 
> > > diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> > > index abb58ab1a1a4..cfb5b3d66b76 100644
> > > --- a/drivers/mfd/Kconfig
> > > +++ b/drivers/mfd/Kconfig
> > > @@ -1547,6 +1547,20 @@ config MFD_TI_LP873X
> > >  	  This driver can also be built as a module. If so, the module
> > >  	  will be called lp873x.
> > >  
> > > +config MFD_TPS6594X
> > > +	tristate "TI TPS6594X Power Management IC"
> > > +	depends on I2C
> > > +	select MFD_CORE
> > > +	select REGMAP_I2C
> > > +	help
> > > +	  If you say yes here then you get support for the TPS6594X series of
> > > +	  Power Management Integrated Circuits (PMIC).
> > > +	  These include voltage regulators, RTS, configurable
> > > +	  General Purpose Outputs (GPO) that are used in portable devices.
> > > +
> > > +	  This driver can also be built as a module. If so, the module
> > > +	  will be called tps7694x.
> > > +
> > >  config MFD_TI_LP87565
> > >  	tristate "TI LP87565 Power Management IC"
> > >  	depends on I2C && OF
> > > diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
> > > index 858cacf659d6..7ff6a8a57d55 100644
> > > --- a/drivers/mfd/Makefile
> > > +++ b/drivers/mfd/Makefile
> > > @@ -105,6 +105,7 @@ obj-$(CONFIG_MFD_TPS65910)	+= tps65910.o
> > >  obj-$(CONFIG_MFD_TPS65912)	+= tps65912-core.o
> > >  obj-$(CONFIG_MFD_TPS65912_I2C)	+= tps65912-i2c.o
> > >  obj-$(CONFIG_MFD_TPS65912_SPI)  += tps65912-spi.o
> > > +obj-$(CONFIG_MFD_TPS6594X)	+= tps6594x.o
> > >  obj-$(CONFIG_MENELAUS)		+= menelaus.o
> > >  
> > >  obj-$(CONFIG_TWL4030_CORE)	+= twl-core.o twl4030-irq.o twl6030-irq.o
> > > diff --git a/drivers/mfd/tps6594x.c b/drivers/mfd/tps6594x.c
> > > new file mode 100644
> > > index 000000000000..519162cc1fbe
> > > --- /dev/null
> > > +++ b/drivers/mfd/tps6594x.c
> > > @@ -0,0 +1,106 @@
> > > +// SPDX-License-Identifier: GPL-2.0-or-later
> > > +/*
> > > + * tps6594x.c  --  TI TPS6594x chip family multi-function driver
> > 
> > No filenames in comments please.
> > 
> > Also, there are too many spaces around the '--'.
> > 
> > It's not a "multi-function driver" it's a PMIC Core driver.
> >
> 
> Noted. Will change to PMIC core driver to be more concise.
> 
> > > + * Copyright (C) 2022 Texas Instruments Incorporated - https://www.ti.com/
> > > + *
> > > + * Author: Keerthy <j-keerthy@ti.com>
> > > + */
> > > +
> > > +#include <linux/interrupt.h>
> > > +#include <linux/mfd/core.h>
> > > +#include <linux/module.h>
> > > +#include <linux/of_device.h>
> > > +#include <linux/i2c.h>
> > > +#include <linux/regmap.h>
> > 
> > Alphabetical.
> > 
> > > +#include <linux/mfd/tps6594x.h>
> > > +
> > > +static const struct regmap_config tps6594x_regmap_config = {
> > > +	.reg_bits = 8,
> > > +	.val_bits = 8,
> > > +	.max_register = TPS6594X_REG_MAX,
> > > +};
> > > +
> > > +static const struct mfd_cell tps6594x_cells[] = {
> > > +	{ .name = "tps6594x-rtc", },
> > > +};
> > 
> > Where are the rest of the devices?
> > 
> > This is not an MFD with only one device.
> 
> There are other devices, however there isn't any drivers currently for them
> just the RTC. Should there be placeholders for the gpio, and regulators even
> if support currently doesn't exist.

If support doesn't exist for the other devices, just submit an
independent RTC driver.

-- 
Lee Jones [李琼斯]

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

end of thread, other threads:[~2022-08-11  7:04 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-05  6:43 [PATCH 0/4] mfd: add tps6594x support for j7200 platform Matt Ranostay
2022-08-05  6:43 ` [PATCH 1/4] Documentation: tps6594x: Add DT bindings for the TPS6594x PMIC Matt Ranostay
2022-08-05 14:14   ` Rob Herring
2022-08-05  6:43 ` [PATCH 2/4] MFD: TPS6594x: Add new mfd device for " Matt Ranostay
2022-08-10 11:27   ` Lee Jones
2022-08-11  6:33     ` Matt Ranostay
2022-08-11  7:04       ` Lee Jones
2022-08-05  6:43 ` [PATCH 3/4] rtc: rtc-tps6594x: Add support for TPS6594X PMIC RTC Matt Ranostay
2022-08-05  6:43 ` [PATCH 4/4] arm64: dts: ti: k3-j7200-common-proc-board: Add TPS6594x PMIC node Matt Ranostay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).