All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/7] mfd: add tps6594x support for Jacinto platforms
@ 2022-11-09  6:55 ` Matt Ranostay
  0 siblings, 0 replies; 42+ messages in thread
From: Matt Ranostay @ 2022-11-09  6:55 UTC (permalink / raw)
  To: brgl, lee, linus.walleij, kristo, alexandre.belloni, a.zummo,
	krzysztof.kozlowski+dt, robh, vigneshr
  Cc: linux-arm-kernel, devicetree, linux-rtc, linux-gpio, Matt Ranostay

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

Additionally, add usage of the PMIC for the various Jacintor platforms
devicetree's.

Changes from v1:
* Corrected devicetree documentation issues found with dt-schema
* Changed MFD references to PMIC reflecting the more valid use of driver
* Cleaning up variable naming and ordering within functions
* Adding gpio + regulator cells for upcoming driver support 
* Switching from .probe to .probe_new API
* Revising comments within drivers to be more concise
* Adding device tree nodes for j721s2 and j721e platforms

Changes from v2:
* Adding gpio-tps6594x driver support
* Enabling gpio cell in MFD driver
* Adding device tree nodes for k3-*dts platforms

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

Matt Ranostay (4):
  Documentation: tps6594x: Add DT bindings for the TPS6594x PMIC
  gpio: tps6594x: add GPIO support for TPS6594x PMIC
  arm64: dts: ti: k3-j721e-common-proc-board: Add TPS6594x PMIC node
  arm64: dts: ti: k3-j721s2-common-proc-board: Add TPS6594x PMIC node

 .../devicetree/bindings/mfd/ti,tps6594x.yaml  |  67 +++++++
 .../dts/ti/k3-j7200-common-proc-board.dts     |  17 ++
 .../dts/ti/k3-j721e-common-proc-board.dts     |  17 ++
 .../dts/ti/k3-j721s2-common-proc-board.dts    |  17 ++
 drivers/gpio/Kconfig                          |   7 +
 drivers/gpio/Makefile                         |   1 +
 drivers/gpio/gpio-tps6594x.c                  | 142 ++++++++++++++
 drivers/mfd/Kconfig                           |  14 ++
 drivers/mfd/Makefile                          |   1 +
 drivers/mfd/tps6594x.c                        | 120 ++++++++++++
 drivers/rtc/Kconfig                           |  10 +
 drivers/rtc/Makefile                          |   1 +
 drivers/rtc/rtc-tps6594x.c                    | 181 ++++++++++++++++++
 include/linux/mfd/tps6594x.h                  |  90 +++++++++
 14 files changed, 685 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/ti,tps6594x.yaml
 create mode 100644 drivers/gpio/gpio-tps6594x.c
 create mode 100644 drivers/mfd/tps6594x.c
 create mode 100644 drivers/rtc/rtc-tps6594x.c
 create mode 100644 include/linux/mfd/tps6594x.h

-- 
2.38.GIT


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

* [PATCH v3 0/7] mfd: add tps6594x support for Jacinto platforms
@ 2022-11-09  6:55 ` Matt Ranostay
  0 siblings, 0 replies; 42+ messages in thread
From: Matt Ranostay @ 2022-11-09  6:55 UTC (permalink / raw)
  To: brgl, lee, linus.walleij, kristo, alexandre.belloni, a.zummo,
	krzysztof.kozlowski+dt, robh, vigneshr
  Cc: linux-arm-kernel, devicetree, linux-rtc, linux-gpio, Matt Ranostay

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

Additionally, add usage of the PMIC for the various Jacintor platforms
devicetree's.

Changes from v1:
* Corrected devicetree documentation issues found with dt-schema
* Changed MFD references to PMIC reflecting the more valid use of driver
* Cleaning up variable naming and ordering within functions
* Adding gpio + regulator cells for upcoming driver support 
* Switching from .probe to .probe_new API
* Revising comments within drivers to be more concise
* Adding device tree nodes for j721s2 and j721e platforms

Changes from v2:
* Adding gpio-tps6594x driver support
* Enabling gpio cell in MFD driver
* Adding device tree nodes for k3-*dts platforms

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

Matt Ranostay (4):
  Documentation: tps6594x: Add DT bindings for the TPS6594x PMIC
  gpio: tps6594x: add GPIO support for TPS6594x PMIC
  arm64: dts: ti: k3-j721e-common-proc-board: Add TPS6594x PMIC node
  arm64: dts: ti: k3-j721s2-common-proc-board: Add TPS6594x PMIC node

 .../devicetree/bindings/mfd/ti,tps6594x.yaml  |  67 +++++++
 .../dts/ti/k3-j7200-common-proc-board.dts     |  17 ++
 .../dts/ti/k3-j721e-common-proc-board.dts     |  17 ++
 .../dts/ti/k3-j721s2-common-proc-board.dts    |  17 ++
 drivers/gpio/Kconfig                          |   7 +
 drivers/gpio/Makefile                         |   1 +
 drivers/gpio/gpio-tps6594x.c                  | 142 ++++++++++++++
 drivers/mfd/Kconfig                           |  14 ++
 drivers/mfd/Makefile                          |   1 +
 drivers/mfd/tps6594x.c                        | 120 ++++++++++++
 drivers/rtc/Kconfig                           |  10 +
 drivers/rtc/Makefile                          |   1 +
 drivers/rtc/rtc-tps6594x.c                    | 181 ++++++++++++++++++
 include/linux/mfd/tps6594x.h                  |  90 +++++++++
 14 files changed, 685 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/ti,tps6594x.yaml
 create mode 100644 drivers/gpio/gpio-tps6594x.c
 create mode 100644 drivers/mfd/tps6594x.c
 create mode 100644 drivers/rtc/rtc-tps6594x.c
 create mode 100644 include/linux/mfd/tps6594x.h

-- 
2.38.GIT


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v3 1/7] Documentation: tps6594x: Add DT bindings for the TPS6594x PMIC
  2022-11-09  6:55 ` Matt Ranostay
@ 2022-11-09  6:55   ` Matt Ranostay
  -1 siblings, 0 replies; 42+ messages in thread
From: Matt Ranostay @ 2022-11-09  6:55 UTC (permalink / raw)
  To: brgl, lee, linus.walleij, kristo, alexandre.belloni, a.zummo,
	krzysztof.kozlowski+dt, robh, vigneshr
  Cc: linux-arm-kernel, devicetree, linux-rtc, linux-gpio, Matt Ranostay

Signed-off-by: Matt Ranostay <mranostay@ti.com>
---
 .../devicetree/bindings/mfd/ti,tps6594x.yaml  | 67 +++++++++++++++++++
 1 file changed, 67 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..be87f0037bf9
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/ti,tps6594x.yaml
@@ -0,0 +1,67 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/ti,tps6594x.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: TPS6594x Power Management Integrated Circuit (PMIC)
+
+maintainers:
+  - Keerthy <j-keerthy@ti.com>
+
+properties:
+  compatible:
+    contains:
+      enum:
+        - ti,tps6594x
+
+  reg:
+    const: 0x48
+    description: I2C slave address
+
+  ti,system-power-controller:
+    type: boolean
+    description: PMIC is controlling the system power.
+
+  rtc:
+    type: object
+    $ref: /schemas/rtc/rtc.yaml#
+    unevaluatedProperties: false
+    properties:
+      compatible:
+        const: ti,tps6594x-rtc
+
+  gpio:
+    type: object
+    unevaluatedProperties: false
+    properties:
+      compatible:
+        const: ti,tps6594x-gpio
+
+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";
+            };
+
+            gpio {
+                compatible = "ti,tps6594x-gpio";
+            };
+        };
+    };
+
+...
-- 
2.38.GIT


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

* [PATCH v3 1/7] Documentation: tps6594x: Add DT bindings for the TPS6594x PMIC
@ 2022-11-09  6:55   ` Matt Ranostay
  0 siblings, 0 replies; 42+ messages in thread
From: Matt Ranostay @ 2022-11-09  6:55 UTC (permalink / raw)
  To: brgl, lee, linus.walleij, kristo, alexandre.belloni, a.zummo,
	krzysztof.kozlowski+dt, robh, vigneshr
  Cc: linux-arm-kernel, devicetree, linux-rtc, linux-gpio, Matt Ranostay

Signed-off-by: Matt Ranostay <mranostay@ti.com>
---
 .../devicetree/bindings/mfd/ti,tps6594x.yaml  | 67 +++++++++++++++++++
 1 file changed, 67 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..be87f0037bf9
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/ti,tps6594x.yaml
@@ -0,0 +1,67 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/ti,tps6594x.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: TPS6594x Power Management Integrated Circuit (PMIC)
+
+maintainers:
+  - Keerthy <j-keerthy@ti.com>
+
+properties:
+  compatible:
+    contains:
+      enum:
+        - ti,tps6594x
+
+  reg:
+    const: 0x48
+    description: I2C slave address
+
+  ti,system-power-controller:
+    type: boolean
+    description: PMIC is controlling the system power.
+
+  rtc:
+    type: object
+    $ref: /schemas/rtc/rtc.yaml#
+    unevaluatedProperties: false
+    properties:
+      compatible:
+        const: ti,tps6594x-rtc
+
+  gpio:
+    type: object
+    unevaluatedProperties: false
+    properties:
+      compatible:
+        const: ti,tps6594x-gpio
+
+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";
+            };
+
+            gpio {
+                compatible = "ti,tps6594x-gpio";
+            };
+        };
+    };
+
+...
-- 
2.38.GIT


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v3 2/7] MFD: TPS6594x: Add new PMIC device driver for TPS6594x chips
  2022-11-09  6:55 ` Matt Ranostay
@ 2022-11-09  6:55   ` Matt Ranostay
  -1 siblings, 0 replies; 42+ messages in thread
From: Matt Ranostay @ 2022-11-09  6:55 UTC (permalink / raw)
  To: brgl, lee, linus.walleij, kristo, alexandre.belloni, a.zummo,
	krzysztof.kozlowski+dt, robh, vigneshr
  Cc: linux-arm-kernel, devicetree, linux-rtc, linux-gpio, Keerthy,
	Matt Ranostay

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

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

- 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       | 120 +++++++++++++++++++++++++++++++++++
 include/linux/mfd/tps6594x.h |  84 ++++++++++++++++++++++++
 4 files changed, 219 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 6e920442366c..9a6dc6b69058 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -1596,6 +1596,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 && OF
+	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 tps6594x.
+
 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 4dd479212b3a..51d7bfcd0a27 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -101,6 +101,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..0de7946b6b8b
--- /dev/null
+++ b/drivers/mfd/tps6594x.c
@@ -0,0 +1,120 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Driver for tps6594x PMIC chips
+ *
+ * Copyright (C) 2022 Texas Instruments Incorporated - https://www.ti.com/
+ * Author: Keerthy <j-keerthy@ti.com>
+ */
+
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/mfd/core.h>
+#include <linux/mfd/tps6594x.h>
+#include <linux/module.h>
+#include <linux/i2c.h>
+#include <linux/regmap.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-gpio" },
+	{ .name = "tps6594x-rtc" },
+};
+
+static struct tps6594x *tps;
+
+static void tps6594x_power_off(void)
+{
+	regmap_write(tps->regmap, TPS6594X_FSM_NSLEEP_TRIGGERS,
+		TPS6594X_FSM_NSLEEP_NSLEEP1B | TPS6594X_FSM_NSLEEP_NSLEEP2B);
+
+	regmap_write(tps->regmap, TPS6594X_INT_STARTUP,
+		TPS6594X_INT_STARTUP_NPWRON_START_INT |
+		TPS6594X_INT_STARTUP_ENABLE_INT | TPS6594X_INT_STARTUP_RTC_INT |
+		TPS6594X_INT_STARTUP_SOFT_REBOOT_INT);
+
+	regmap_write(tps->regmap, TPS6594X_INT_MISC,
+		TPS6594X_INT_MISC_BIST_PASS_INT |
+		TPS6594X_INT_MISC_EXT_CLK_INT | TPS6594X_INT_MISC_TWARN_INT);
+
+	regmap_write(tps->regmap, TPS6594X_CONFIG_1,
+		TPS6594X_CONFIG_NSLEEP1_MASK | TPS6594X_CONFIG_NSLEEP2_MASK);
+
+	regmap_write(tps->regmap, TPS6594X_FSM_I2C_TRIGGERS,
+		TPS6594X_FSM_I2C_TRIGGERS_I2C0);
+}
+
+static int tps6594x_probe(struct i2c_client *client)
+{
+	struct tps6594x *ddata;
+	struct device_node *node = client->dev.of_node;
+	unsigned int otpid;
+	int ret;
+
+	ddata = devm_kzalloc(&client->dev, sizeof(*ddata), GFP_KERNEL);
+	if (!ddata)
+		return -ENOMEM;
+
+	ddata->dev = &client->dev;
+
+	ddata->regmap = devm_regmap_init_i2c(client, &tps6594x_regmap_config);
+	if (IS_ERR(ddata->regmap)) {
+		ret = PTR_ERR(ddata->regmap);
+		dev_err(ddata->dev,
+			"Failed to initialize register map: %d\n", ret);
+		return ret;
+	}
+
+	ret = regmap_read(ddata->regmap, TPS6594X_REG_DEV_REV, &otpid);
+	if (ret) {
+		dev_err(ddata->dev, "Failed to read OTP ID\n");
+		return ret;
+	}
+
+	ddata->rev = otpid;
+	i2c_set_clientdata(client, ddata);
+
+	ret = mfd_add_devices(ddata->dev, PLATFORM_DEVID_AUTO, tps6594x_cells,
+			      ARRAY_SIZE(tps6594x_cells), NULL, 0, NULL);
+	if (ret) {
+		dev_err(ddata->dev, "Failed to register cells\n");
+		return ret;
+	}
+
+	tps = ddata;
+
+	if (of_property_read_bool(node, "ti,system-power-controller"))
+		pm_power_off = tps6594x_power_off;
+
+	return 0;
+}
+
+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_new	= tps6594x_probe,
+	.id_table	= tps6594x_id_table,
+};
+module_i2c_driver(tps6594x_driver);
+
+MODULE_AUTHOR("J Keerthy <j-keerthy@ti.com>");
+MODULE_DESCRIPTION("TPS6594X PMIC 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..5a6af0da9223
--- /dev/null
+++ b/include/linux/mfd/tps6594x.h
@@ -0,0 +1,84 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Core driver interface for TI TPS6594x PMIC family
+ *
+ * Copyright (C) 2022 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#ifndef __MFD_TPS6594X_H
+#define __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_INT_STARTUP_NPWRON_START_INT	BIT(0)
+#define TPS6594X_INT_STARTUP_ENABLE_INT		BIT(1)
+#define TPS6594X_INT_STARTUP_RTC_INT		BIT(2)
+#define TPS6594X_INT_STARTUP_FSD_INT		BIT(4)
+#define TPS6594X_INT_STARTUP_SOFT_REBOOT_INT	BIT(5)
+
+#define TPS6594X_INT_MISC_BIST_PASS_INT		BIT(0)
+#define TPS6594X_INT_MISC_EXT_CLK_INT		BIT(1)
+#define TPS6594X_INT_MISC_TWARN_INT		BIT(3)
+
+#define TPS6594X_CONFIG_NSLEEP1_MASK		BIT(6)
+#define TPS6594X_CONFIG_NSLEEP2_MASK		BIT(7)
+
+#define TPS6594X_FSM_I2C_TRIGGERS_I2C0		BIT(0)
+
+#define TPS6594X_FSM_NSLEEP_NSLEEP1B		BIT(0)
+#define TPS6594X_FSM_NSLEEP_NSLEEP2B		BIT(1)
+
+#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 /* __MFD_TPS6594X_H */
-- 
2.38.GIT


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

* [PATCH v3 2/7] MFD: TPS6594x: Add new PMIC device driver for TPS6594x chips
@ 2022-11-09  6:55   ` Matt Ranostay
  0 siblings, 0 replies; 42+ messages in thread
From: Matt Ranostay @ 2022-11-09  6:55 UTC (permalink / raw)
  To: brgl, lee, linus.walleij, kristo, alexandre.belloni, a.zummo,
	krzysztof.kozlowski+dt, robh, vigneshr
  Cc: linux-arm-kernel, devicetree, linux-rtc, linux-gpio, Keerthy,
	Matt Ranostay

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

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

- 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       | 120 +++++++++++++++++++++++++++++++++++
 include/linux/mfd/tps6594x.h |  84 ++++++++++++++++++++++++
 4 files changed, 219 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 6e920442366c..9a6dc6b69058 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -1596,6 +1596,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 && OF
+	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 tps6594x.
+
 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 4dd479212b3a..51d7bfcd0a27 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -101,6 +101,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..0de7946b6b8b
--- /dev/null
+++ b/drivers/mfd/tps6594x.c
@@ -0,0 +1,120 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Driver for tps6594x PMIC chips
+ *
+ * Copyright (C) 2022 Texas Instruments Incorporated - https://www.ti.com/
+ * Author: Keerthy <j-keerthy@ti.com>
+ */
+
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/mfd/core.h>
+#include <linux/mfd/tps6594x.h>
+#include <linux/module.h>
+#include <linux/i2c.h>
+#include <linux/regmap.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-gpio" },
+	{ .name = "tps6594x-rtc" },
+};
+
+static struct tps6594x *tps;
+
+static void tps6594x_power_off(void)
+{
+	regmap_write(tps->regmap, TPS6594X_FSM_NSLEEP_TRIGGERS,
+		TPS6594X_FSM_NSLEEP_NSLEEP1B | TPS6594X_FSM_NSLEEP_NSLEEP2B);
+
+	regmap_write(tps->regmap, TPS6594X_INT_STARTUP,
+		TPS6594X_INT_STARTUP_NPWRON_START_INT |
+		TPS6594X_INT_STARTUP_ENABLE_INT | TPS6594X_INT_STARTUP_RTC_INT |
+		TPS6594X_INT_STARTUP_SOFT_REBOOT_INT);
+
+	regmap_write(tps->regmap, TPS6594X_INT_MISC,
+		TPS6594X_INT_MISC_BIST_PASS_INT |
+		TPS6594X_INT_MISC_EXT_CLK_INT | TPS6594X_INT_MISC_TWARN_INT);
+
+	regmap_write(tps->regmap, TPS6594X_CONFIG_1,
+		TPS6594X_CONFIG_NSLEEP1_MASK | TPS6594X_CONFIG_NSLEEP2_MASK);
+
+	regmap_write(tps->regmap, TPS6594X_FSM_I2C_TRIGGERS,
+		TPS6594X_FSM_I2C_TRIGGERS_I2C0);
+}
+
+static int tps6594x_probe(struct i2c_client *client)
+{
+	struct tps6594x *ddata;
+	struct device_node *node = client->dev.of_node;
+	unsigned int otpid;
+	int ret;
+
+	ddata = devm_kzalloc(&client->dev, sizeof(*ddata), GFP_KERNEL);
+	if (!ddata)
+		return -ENOMEM;
+
+	ddata->dev = &client->dev;
+
+	ddata->regmap = devm_regmap_init_i2c(client, &tps6594x_regmap_config);
+	if (IS_ERR(ddata->regmap)) {
+		ret = PTR_ERR(ddata->regmap);
+		dev_err(ddata->dev,
+			"Failed to initialize register map: %d\n", ret);
+		return ret;
+	}
+
+	ret = regmap_read(ddata->regmap, TPS6594X_REG_DEV_REV, &otpid);
+	if (ret) {
+		dev_err(ddata->dev, "Failed to read OTP ID\n");
+		return ret;
+	}
+
+	ddata->rev = otpid;
+	i2c_set_clientdata(client, ddata);
+
+	ret = mfd_add_devices(ddata->dev, PLATFORM_DEVID_AUTO, tps6594x_cells,
+			      ARRAY_SIZE(tps6594x_cells), NULL, 0, NULL);
+	if (ret) {
+		dev_err(ddata->dev, "Failed to register cells\n");
+		return ret;
+	}
+
+	tps = ddata;
+
+	if (of_property_read_bool(node, "ti,system-power-controller"))
+		pm_power_off = tps6594x_power_off;
+
+	return 0;
+}
+
+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_new	= tps6594x_probe,
+	.id_table	= tps6594x_id_table,
+};
+module_i2c_driver(tps6594x_driver);
+
+MODULE_AUTHOR("J Keerthy <j-keerthy@ti.com>");
+MODULE_DESCRIPTION("TPS6594X PMIC 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..5a6af0da9223
--- /dev/null
+++ b/include/linux/mfd/tps6594x.h
@@ -0,0 +1,84 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Core driver interface for TI TPS6594x PMIC family
+ *
+ * Copyright (C) 2022 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#ifndef __MFD_TPS6594X_H
+#define __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_INT_STARTUP_NPWRON_START_INT	BIT(0)
+#define TPS6594X_INT_STARTUP_ENABLE_INT		BIT(1)
+#define TPS6594X_INT_STARTUP_RTC_INT		BIT(2)
+#define TPS6594X_INT_STARTUP_FSD_INT		BIT(4)
+#define TPS6594X_INT_STARTUP_SOFT_REBOOT_INT	BIT(5)
+
+#define TPS6594X_INT_MISC_BIST_PASS_INT		BIT(0)
+#define TPS6594X_INT_MISC_EXT_CLK_INT		BIT(1)
+#define TPS6594X_INT_MISC_TWARN_INT		BIT(3)
+
+#define TPS6594X_CONFIG_NSLEEP1_MASK		BIT(6)
+#define TPS6594X_CONFIG_NSLEEP2_MASK		BIT(7)
+
+#define TPS6594X_FSM_I2C_TRIGGERS_I2C0		BIT(0)
+
+#define TPS6594X_FSM_NSLEEP_NSLEEP1B		BIT(0)
+#define TPS6594X_FSM_NSLEEP_NSLEEP2B		BIT(1)
+
+#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 /* __MFD_TPS6594X_H */
-- 
2.38.GIT


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v3 3/7] rtc: rtc-tps6594x: Add support for TPS6594X PMIC RTC
  2022-11-09  6:55 ` Matt Ranostay
@ 2022-11-09  6:55   ` Matt Ranostay
  -1 siblings, 0 replies; 42+ messages in thread
From: Matt Ranostay @ 2022-11-09  6:55 UTC (permalink / raw)
  To: brgl, lee, linus.walleij, kristo, alexandre.belloni, a.zummo,
	krzysztof.kozlowski+dt, robh, vigneshr
  Cc: linux-arm-kernel, devicetree, linux-rtc, linux-gpio, 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 35298c651730..0adb2c2570b8 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -588,6 +588,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 c2d474985919..cf46d88bc4b0 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -176,6 +176,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.38.GIT


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

* [PATCH v3 3/7] rtc: rtc-tps6594x: Add support for TPS6594X PMIC RTC
@ 2022-11-09  6:55   ` Matt Ranostay
  0 siblings, 0 replies; 42+ messages in thread
From: Matt Ranostay @ 2022-11-09  6:55 UTC (permalink / raw)
  To: brgl, lee, linus.walleij, kristo, alexandre.belloni, a.zummo,
	krzysztof.kozlowski+dt, robh, vigneshr
  Cc: linux-arm-kernel, devicetree, linux-rtc, linux-gpio, 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 35298c651730..0adb2c2570b8 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -588,6 +588,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 c2d474985919..cf46d88bc4b0 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -176,6 +176,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.38.GIT


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v3 4/7] gpio: tps6594x: add GPIO support for TPS6594x PMIC
  2022-11-09  6:55 ` Matt Ranostay
@ 2022-11-09  6:55   ` Matt Ranostay
  -1 siblings, 0 replies; 42+ messages in thread
From: Matt Ranostay @ 2022-11-09  6:55 UTC (permalink / raw)
  To: brgl, lee, linus.walleij, kristo, alexandre.belloni, a.zummo,
	krzysztof.kozlowski+dt, robh, vigneshr
  Cc: linux-arm-kernel, devicetree, linux-rtc, linux-gpio,
	Matt Ranostay, Keerthy

Add support for TPS6594X PMICs GPIO interface that has 11 that can be
configured as input or outputs.

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

diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 8c756cb29214..0225e6bddf0a 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -1405,6 +1405,13 @@ config GPIO_TPS65912
 	help
 	  This driver supports TPS65912 GPIO chip.
 
+config GPIO_TPS6594X
+	tristate "TI TPS6594X GPIO driver"
+	depends on MFD_TPS6594X
+	help
+	  Select this option to enable GPIO driver for the TPS6954X
+	  PMIC chip family. There are 11 GPIOs that can be configured.
+
 config GPIO_TPS68470
 	tristate "TPS68470 GPIO"
 	depends on INTEL_SKL_INT3472
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 8629e9eaf79e..e67a9b787b09 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -158,6 +158,7 @@ obj-$(CONFIG_GPIO_TPS65218)		+= gpio-tps65218.o
 obj-$(CONFIG_GPIO_TPS6586X)		+= gpio-tps6586x.o
 obj-$(CONFIG_GPIO_TPS65910)		+= gpio-tps65910.o
 obj-$(CONFIG_GPIO_TPS65912)		+= gpio-tps65912.o
+obj-$(CONFIG_GPIO_TPS6594X)		+= gpio-tps6594x.o
 obj-$(CONFIG_GPIO_TPS68470)		+= gpio-tps68470.o
 obj-$(CONFIG_GPIO_TQMX86)		+= gpio-tqmx86.o
 obj-$(CONFIG_GPIO_TS4800)		+= gpio-ts4800.o
diff --git a/drivers/gpio/gpio-tps6594x.c b/drivers/gpio/gpio-tps6594x.c
new file mode 100644
index 000000000000..f530ac17f73f
--- /dev/null
+++ b/drivers/gpio/gpio-tps6594x.c
@@ -0,0 +1,142 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * GPIO driver for TI TPS6594x PMICs
+ *
+ * Copyright (C) 2022 Texas Instruments Incorporated - http://www.ti.com/
+ */
+
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+
+#include <linux/gpio/driver.h>
+#include <linux/mfd/tps6594x.h>
+
+#define GPIO_CFG_MASK	BIT(0)
+#define NGPIOS_PER_REG	8
+
+struct tps6594x_gpio {
+	struct gpio_chip gpio_chip;
+	struct tps6594x *tps;
+};
+
+static int tps6594x_gpio_get_direction(struct gpio_chip *gc, unsigned int offset)
+{
+	struct tps6594x_gpio *gpio = gpiochip_get_data(gc);
+	int ret, val;
+
+	ret = regmap_read(gpio->tps->regmap, TPS6594X_GPIO1_CONF + offset, &val);
+	if (ret)
+		return ret;
+
+	if (val & GPIO_CFG_MASK)
+		return GPIO_LINE_DIRECTION_OUT;
+
+	return GPIO_LINE_DIRECTION_IN;
+}
+
+static int tps6594x_gpio_direction_input(struct gpio_chip *gc, unsigned int offset)
+{
+	struct tps6594x_gpio *gpio = gpiochip_get_data(gc);
+
+	return regmap_update_bits(gpio->tps->regmap, TPS6594X_GPIO1_CONF + offset,
+				  GPIO_CFG_MASK, 0);
+}
+
+static int tps6594x_gpio_direction_output(struct gpio_chip *gc, unsigned int offset, int value)
+{
+	struct tps6594x_gpio *gpio = gpiochip_get_data(gc);
+	unsigned int reg = TPS6594X_GPIO_OUT_1, shift = offset;
+
+	if (shift >= NGPIOS_PER_REG) {
+		reg = TPS6594X_GPIO_OUT_2;
+		shift -= NGPIOS_PER_REG;
+	}
+
+	regmap_update_bits(gpio->tps->regmap, reg, BIT(shift), value ? BIT(shift) : 0);
+
+	return regmap_update_bits(gpio->tps->regmap, TPS6594X_GPIO1_CONF + offset,
+				  GPIO_CFG_MASK, GPIO_CFG_MASK);
+}
+
+static int tps6594x_gpio_get(struct gpio_chip *gc, unsigned int offset)
+{
+	struct tps6594x_gpio *gpio = gpiochip_get_data(gc);
+	unsigned int reg = TPS6594X_GPIO_IN_1;
+	int ret, val;
+
+	if (offset >= NGPIOS_PER_REG) {
+		reg = TPS6594X_GPIO_IN_2;
+		offset -= NGPIOS_PER_REG;
+	}
+
+	ret = regmap_read(gpio->tps->regmap, reg, &val);
+	if (ret)
+		return ret;
+
+	return !!(val & BIT(offset));
+}
+
+static void tps6594x_gpio_set(struct gpio_chip *gc, unsigned int offset,
+			      int value)
+{
+	struct tps6594x_gpio *gpio = gpiochip_get_data(gc);
+	unsigned int reg = TPS6594X_GPIO_OUT_1;
+
+	if (offset >= NGPIOS_PER_REG) {
+		reg = TPS6594X_GPIO_OUT_2;
+		offset -= NGPIOS_PER_REG;
+	}
+
+	regmap_update_bits(gpio->tps->regmap, reg, BIT(offset), value ? BIT(offset) : 0);
+}
+
+static const struct gpio_chip template_chip = {
+	.label			= "tps6594x-gpio",
+	.owner			= THIS_MODULE,
+	.get_direction		= tps6594x_gpio_get_direction,
+	.direction_input	= tps6594x_gpio_direction_input,
+	.direction_output	= tps6594x_gpio_direction_output,
+	.get			= tps6594x_gpio_get,
+	.set			= tps6594x_gpio_set,
+	.base			= -1,
+	.ngpio			= 11,
+	.can_sleep		= true,
+};
+
+static int tps6594x_gpio_probe(struct platform_device *pdev)
+{
+	struct tps6594x *tps = dev_get_drvdata(pdev->dev.parent);
+	struct tps6594x_gpio *gpio;
+
+	gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL);
+	if (!gpio)
+		return -ENOMEM;
+
+	gpio->tps = dev_get_drvdata(pdev->dev.parent);
+	gpio->gpio_chip = template_chip;
+	gpio->gpio_chip.parent = tps->dev;
+
+	return devm_gpiochip_add_data(&pdev->dev, &gpio->gpio_chip, gpio);
+}
+
+static const struct of_device_id of_tps6594x_gpio_match[] = {
+	{ .compatible = "ti,tps6594x-gpio", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, of_tps6594x_gpio_match);
+
+static struct platform_driver tps6594x_gpio_driver = {
+	.driver = {
+		.name = "tps6594x-gpio",
+		.of_match_table = of_match_ptr(of_tps6594x_gpio_match),
+	},
+	.probe = tps6594x_gpio_probe,
+};
+module_platform_driver(tps6594x_gpio_driver);
+
+MODULE_ALIAS("platform:tps6594x-gpio");
+MODULE_AUTHOR("Matt Ranostay <mranostay@ti.com>");
+MODULE_DESCRIPTION("TPS6594X GPIO driver");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/mfd/tps6594x.h b/include/linux/mfd/tps6594x.h
index 5a6af0da9223..c2440f5f43d3 100644
--- a/include/linux/mfd/tps6594x.h
+++ b/include/linux/mfd/tps6594x.h
@@ -21,6 +21,12 @@
 #define TPS6594X_FSM_I2C_TRIGGERS		0x85
 #define TPS6594X_FSM_NSLEEP_TRIGGERS		0x86
 
+#define TPS6594X_GPIO1_CONF			0x31
+#define TPS6594X_GPIO_OUT_1			0x3d
+#define TPS6594X_GPIO_OUT_2			0x3e
+#define TPS6594X_GPIO_IN_1			0x3f
+#define TPS6594X_GPIO_IN_2			0x40
+
 #define TPS6594X_RTC_SECONDS			0xb5
 #define TPS6594X_RTC_MINUTES			0xb6
 #define TPS6594X_RTC_HOURS			0xb7
-- 
2.38.GIT


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

* [PATCH v3 4/7] gpio: tps6594x: add GPIO support for TPS6594x PMIC
@ 2022-11-09  6:55   ` Matt Ranostay
  0 siblings, 0 replies; 42+ messages in thread
From: Matt Ranostay @ 2022-11-09  6:55 UTC (permalink / raw)
  To: brgl, lee, linus.walleij, kristo, alexandre.belloni, a.zummo,
	krzysztof.kozlowski+dt, robh, vigneshr
  Cc: linux-arm-kernel, devicetree, linux-rtc, linux-gpio,
	Matt Ranostay, Keerthy

Add support for TPS6594X PMICs GPIO interface that has 11 that can be
configured as input or outputs.

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

diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 8c756cb29214..0225e6bddf0a 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -1405,6 +1405,13 @@ config GPIO_TPS65912
 	help
 	  This driver supports TPS65912 GPIO chip.
 
+config GPIO_TPS6594X
+	tristate "TI TPS6594X GPIO driver"
+	depends on MFD_TPS6594X
+	help
+	  Select this option to enable GPIO driver for the TPS6954X
+	  PMIC chip family. There are 11 GPIOs that can be configured.
+
 config GPIO_TPS68470
 	tristate "TPS68470 GPIO"
 	depends on INTEL_SKL_INT3472
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 8629e9eaf79e..e67a9b787b09 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -158,6 +158,7 @@ obj-$(CONFIG_GPIO_TPS65218)		+= gpio-tps65218.o
 obj-$(CONFIG_GPIO_TPS6586X)		+= gpio-tps6586x.o
 obj-$(CONFIG_GPIO_TPS65910)		+= gpio-tps65910.o
 obj-$(CONFIG_GPIO_TPS65912)		+= gpio-tps65912.o
+obj-$(CONFIG_GPIO_TPS6594X)		+= gpio-tps6594x.o
 obj-$(CONFIG_GPIO_TPS68470)		+= gpio-tps68470.o
 obj-$(CONFIG_GPIO_TQMX86)		+= gpio-tqmx86.o
 obj-$(CONFIG_GPIO_TS4800)		+= gpio-ts4800.o
diff --git a/drivers/gpio/gpio-tps6594x.c b/drivers/gpio/gpio-tps6594x.c
new file mode 100644
index 000000000000..f530ac17f73f
--- /dev/null
+++ b/drivers/gpio/gpio-tps6594x.c
@@ -0,0 +1,142 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * GPIO driver for TI TPS6594x PMICs
+ *
+ * Copyright (C) 2022 Texas Instruments Incorporated - http://www.ti.com/
+ */
+
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+
+#include <linux/gpio/driver.h>
+#include <linux/mfd/tps6594x.h>
+
+#define GPIO_CFG_MASK	BIT(0)
+#define NGPIOS_PER_REG	8
+
+struct tps6594x_gpio {
+	struct gpio_chip gpio_chip;
+	struct tps6594x *tps;
+};
+
+static int tps6594x_gpio_get_direction(struct gpio_chip *gc, unsigned int offset)
+{
+	struct tps6594x_gpio *gpio = gpiochip_get_data(gc);
+	int ret, val;
+
+	ret = regmap_read(gpio->tps->regmap, TPS6594X_GPIO1_CONF + offset, &val);
+	if (ret)
+		return ret;
+
+	if (val & GPIO_CFG_MASK)
+		return GPIO_LINE_DIRECTION_OUT;
+
+	return GPIO_LINE_DIRECTION_IN;
+}
+
+static int tps6594x_gpio_direction_input(struct gpio_chip *gc, unsigned int offset)
+{
+	struct tps6594x_gpio *gpio = gpiochip_get_data(gc);
+
+	return regmap_update_bits(gpio->tps->regmap, TPS6594X_GPIO1_CONF + offset,
+				  GPIO_CFG_MASK, 0);
+}
+
+static int tps6594x_gpio_direction_output(struct gpio_chip *gc, unsigned int offset, int value)
+{
+	struct tps6594x_gpio *gpio = gpiochip_get_data(gc);
+	unsigned int reg = TPS6594X_GPIO_OUT_1, shift = offset;
+
+	if (shift >= NGPIOS_PER_REG) {
+		reg = TPS6594X_GPIO_OUT_2;
+		shift -= NGPIOS_PER_REG;
+	}
+
+	regmap_update_bits(gpio->tps->regmap, reg, BIT(shift), value ? BIT(shift) : 0);
+
+	return regmap_update_bits(gpio->tps->regmap, TPS6594X_GPIO1_CONF + offset,
+				  GPIO_CFG_MASK, GPIO_CFG_MASK);
+}
+
+static int tps6594x_gpio_get(struct gpio_chip *gc, unsigned int offset)
+{
+	struct tps6594x_gpio *gpio = gpiochip_get_data(gc);
+	unsigned int reg = TPS6594X_GPIO_IN_1;
+	int ret, val;
+
+	if (offset >= NGPIOS_PER_REG) {
+		reg = TPS6594X_GPIO_IN_2;
+		offset -= NGPIOS_PER_REG;
+	}
+
+	ret = regmap_read(gpio->tps->regmap, reg, &val);
+	if (ret)
+		return ret;
+
+	return !!(val & BIT(offset));
+}
+
+static void tps6594x_gpio_set(struct gpio_chip *gc, unsigned int offset,
+			      int value)
+{
+	struct tps6594x_gpio *gpio = gpiochip_get_data(gc);
+	unsigned int reg = TPS6594X_GPIO_OUT_1;
+
+	if (offset >= NGPIOS_PER_REG) {
+		reg = TPS6594X_GPIO_OUT_2;
+		offset -= NGPIOS_PER_REG;
+	}
+
+	regmap_update_bits(gpio->tps->regmap, reg, BIT(offset), value ? BIT(offset) : 0);
+}
+
+static const struct gpio_chip template_chip = {
+	.label			= "tps6594x-gpio",
+	.owner			= THIS_MODULE,
+	.get_direction		= tps6594x_gpio_get_direction,
+	.direction_input	= tps6594x_gpio_direction_input,
+	.direction_output	= tps6594x_gpio_direction_output,
+	.get			= tps6594x_gpio_get,
+	.set			= tps6594x_gpio_set,
+	.base			= -1,
+	.ngpio			= 11,
+	.can_sleep		= true,
+};
+
+static int tps6594x_gpio_probe(struct platform_device *pdev)
+{
+	struct tps6594x *tps = dev_get_drvdata(pdev->dev.parent);
+	struct tps6594x_gpio *gpio;
+
+	gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL);
+	if (!gpio)
+		return -ENOMEM;
+
+	gpio->tps = dev_get_drvdata(pdev->dev.parent);
+	gpio->gpio_chip = template_chip;
+	gpio->gpio_chip.parent = tps->dev;
+
+	return devm_gpiochip_add_data(&pdev->dev, &gpio->gpio_chip, gpio);
+}
+
+static const struct of_device_id of_tps6594x_gpio_match[] = {
+	{ .compatible = "ti,tps6594x-gpio", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, of_tps6594x_gpio_match);
+
+static struct platform_driver tps6594x_gpio_driver = {
+	.driver = {
+		.name = "tps6594x-gpio",
+		.of_match_table = of_match_ptr(of_tps6594x_gpio_match),
+	},
+	.probe = tps6594x_gpio_probe,
+};
+module_platform_driver(tps6594x_gpio_driver);
+
+MODULE_ALIAS("platform:tps6594x-gpio");
+MODULE_AUTHOR("Matt Ranostay <mranostay@ti.com>");
+MODULE_DESCRIPTION("TPS6594X GPIO driver");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/mfd/tps6594x.h b/include/linux/mfd/tps6594x.h
index 5a6af0da9223..c2440f5f43d3 100644
--- a/include/linux/mfd/tps6594x.h
+++ b/include/linux/mfd/tps6594x.h
@@ -21,6 +21,12 @@
 #define TPS6594X_FSM_I2C_TRIGGERS		0x85
 #define TPS6594X_FSM_NSLEEP_TRIGGERS		0x86
 
+#define TPS6594X_GPIO1_CONF			0x31
+#define TPS6594X_GPIO_OUT_1			0x3d
+#define TPS6594X_GPIO_OUT_2			0x3e
+#define TPS6594X_GPIO_IN_1			0x3f
+#define TPS6594X_GPIO_IN_2			0x40
+
 #define TPS6594X_RTC_SECONDS			0xb5
 #define TPS6594X_RTC_MINUTES			0xb6
 #define TPS6594X_RTC_HOURS			0xb7
-- 
2.38.GIT


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v3 5/7] arm64: dts: ti: k3-j7200-common-proc-board: Add TPS6594x PMIC node
  2022-11-09  6:55 ` Matt Ranostay
@ 2022-11-09  6:55   ` Matt Ranostay
  -1 siblings, 0 replies; 42+ messages in thread
From: Matt Ranostay @ 2022-11-09  6:55 UTC (permalink / raw)
  To: brgl, lee, linus.walleij, kristo, alexandre.belloni, a.zummo,
	krzysztof.kozlowski+dt, robh, vigneshr
  Cc: linux-arm-kernel, devicetree, linux-rtc, linux-gpio, Keerthy,
	Matt Ranostay

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

Add TPS6594x PMIC, GPIO, and RTC definitions for J7200 common processor
board device tree.

Signed-off-by: Keerthy <j-keerthy@ti.com>
Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
---
 .../boot/dts/ti/k3-j7200-common-proc-board.dts  | 17 +++++++++++++++++
 1 file changed, 17 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 6240856e4863..9514751739fe 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
@@ -333,3 +333,20 @@ &pcie1_ep {
 	num-lanes = <2>;
 	status = "disabled";
 };
+
+&wkup_i2c0 {
+	status = "okay";
+	tps6594x: tps6594x@48 {
+		compatible = "ti,tps6594x";
+		reg = <0x48>;
+		ti,system-power-controller;
+
+		rtc {
+			compatible = "ti,tps6594x-rtc";
+		};
+
+		gpio {
+			compatible = "ti,tps6594x-gpio";
+		};
+	};
+};
-- 
2.38.GIT


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

* [PATCH v3 5/7] arm64: dts: ti: k3-j7200-common-proc-board: Add TPS6594x PMIC node
@ 2022-11-09  6:55   ` Matt Ranostay
  0 siblings, 0 replies; 42+ messages in thread
From: Matt Ranostay @ 2022-11-09  6:55 UTC (permalink / raw)
  To: brgl, lee, linus.walleij, kristo, alexandre.belloni, a.zummo,
	krzysztof.kozlowski+dt, robh, vigneshr
  Cc: linux-arm-kernel, devicetree, linux-rtc, linux-gpio, Keerthy,
	Matt Ranostay

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

Add TPS6594x PMIC, GPIO, and RTC definitions for J7200 common processor
board device tree.

Signed-off-by: Keerthy <j-keerthy@ti.com>
Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
---
 .../boot/dts/ti/k3-j7200-common-proc-board.dts  | 17 +++++++++++++++++
 1 file changed, 17 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 6240856e4863..9514751739fe 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
@@ -333,3 +333,20 @@ &pcie1_ep {
 	num-lanes = <2>;
 	status = "disabled";
 };
+
+&wkup_i2c0 {
+	status = "okay";
+	tps6594x: tps6594x@48 {
+		compatible = "ti,tps6594x";
+		reg = <0x48>;
+		ti,system-power-controller;
+
+		rtc {
+			compatible = "ti,tps6594x-rtc";
+		};
+
+		gpio {
+			compatible = "ti,tps6594x-gpio";
+		};
+	};
+};
-- 
2.38.GIT


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v3 6/7] arm64: dts: ti: k3-j721e-common-proc-board: Add TPS6594x PMIC node
  2022-11-09  6:55 ` Matt Ranostay
@ 2022-11-09  6:55   ` Matt Ranostay
  -1 siblings, 0 replies; 42+ messages in thread
From: Matt Ranostay @ 2022-11-09  6:55 UTC (permalink / raw)
  To: brgl, lee, linus.walleij, kristo, alexandre.belloni, a.zummo,
	krzysztof.kozlowski+dt, robh, vigneshr
  Cc: linux-arm-kernel, devicetree, linux-rtc, linux-gpio, Matt Ranostay

Add TPS6594x PMIC, GPIO, and RTC definitions for J721E common processor
board device tree.

Signed-off-by: Matt Ranostay <mranostay@ti.com>
---
 .../boot/dts/ti/k3-j721e-common-proc-board.dts  | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/arch/arm64/boot/dts/ti/k3-j721e-common-proc-board.dts b/arch/arm64/boot/dts/ti/k3-j721e-common-proc-board.dts
index 1861598f3bb4..93bc7433ab06 100644
--- a/arch/arm64/boot/dts/ti/k3-j721e-common-proc-board.dts
+++ b/arch/arm64/boot/dts/ti/k3-j721e-common-proc-board.dts
@@ -904,3 +904,20 @@ &main_mcan2 {
 	pinctrl-0 = <&main_mcan2_pins_default>;
 	phys = <&transceiver4>;
 };
+
+&wkup_i2c0 {
+	status = "okay";
+	tps6594x: tps6594x@48 {
+		compatible = "ti,tps6594x";
+		reg = <0x48>;
+		ti,system-power-controller;
+
+		rtc {
+			compatible = "ti,tps6594x-rtc";
+		};
+
+		gpio {
+			compatible = "ti,tps6594x-gpio";
+		};
+	};
+};
-- 
2.38.GIT


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

* [PATCH v3 6/7] arm64: dts: ti: k3-j721e-common-proc-board: Add TPS6594x PMIC node
@ 2022-11-09  6:55   ` Matt Ranostay
  0 siblings, 0 replies; 42+ messages in thread
From: Matt Ranostay @ 2022-11-09  6:55 UTC (permalink / raw)
  To: brgl, lee, linus.walleij, kristo, alexandre.belloni, a.zummo,
	krzysztof.kozlowski+dt, robh, vigneshr
  Cc: linux-arm-kernel, devicetree, linux-rtc, linux-gpio, Matt Ranostay

Add TPS6594x PMIC, GPIO, and RTC definitions for J721E common processor
board device tree.

Signed-off-by: Matt Ranostay <mranostay@ti.com>
---
 .../boot/dts/ti/k3-j721e-common-proc-board.dts  | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/arch/arm64/boot/dts/ti/k3-j721e-common-proc-board.dts b/arch/arm64/boot/dts/ti/k3-j721e-common-proc-board.dts
index 1861598f3bb4..93bc7433ab06 100644
--- a/arch/arm64/boot/dts/ti/k3-j721e-common-proc-board.dts
+++ b/arch/arm64/boot/dts/ti/k3-j721e-common-proc-board.dts
@@ -904,3 +904,20 @@ &main_mcan2 {
 	pinctrl-0 = <&main_mcan2_pins_default>;
 	phys = <&transceiver4>;
 };
+
+&wkup_i2c0 {
+	status = "okay";
+	tps6594x: tps6594x@48 {
+		compatible = "ti,tps6594x";
+		reg = <0x48>;
+		ti,system-power-controller;
+
+		rtc {
+			compatible = "ti,tps6594x-rtc";
+		};
+
+		gpio {
+			compatible = "ti,tps6594x-gpio";
+		};
+	};
+};
-- 
2.38.GIT


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v3 7/7] arm64: dts: ti: k3-j721s2-common-proc-board: Add TPS6594x PMIC node
  2022-11-09  6:55 ` Matt Ranostay
@ 2022-11-09  6:55   ` Matt Ranostay
  -1 siblings, 0 replies; 42+ messages in thread
From: Matt Ranostay @ 2022-11-09  6:55 UTC (permalink / raw)
  To: brgl, lee, linus.walleij, kristo, alexandre.belloni, a.zummo,
	krzysztof.kozlowski+dt, robh, vigneshr
  Cc: linux-arm-kernel, devicetree, linux-rtc, linux-gpio, Matt Ranostay

Add TPS6594x PMIC, GPIO, and RTC definitions for j721s2 common processor
board device tree.

Signed-off-by: Matt Ranostay <mranostay@ti.com>
---
 .../boot/dts/ti/k3-j721s2-common-proc-board.dts | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/arch/arm64/boot/dts/ti/k3-j721s2-common-proc-board.dts b/arch/arm64/boot/dts/ti/k3-j721s2-common-proc-board.dts
index a7aa6cf08acd..918c0c8d02cf 100644
--- a/arch/arm64/boot/dts/ti/k3-j721s2-common-proc-board.dts
+++ b/arch/arm64/boot/dts/ti/k3-j721s2-common-proc-board.dts
@@ -309,3 +309,20 @@ &mcu_mcan1 {
 	pinctrl-0 = <&mcu_mcan1_pins_default>;
 	phys = <&transceiver2>;
 };
+
+&wkup_i2c0 {
+	status = "okay";
+	tps6594x: tps6594x@48 {
+		compatible = "ti,tps6594x";
+		reg = <0x48>;
+		ti,system-power-controller;
+
+		rtc {
+			compatible = "ti,tps6594x-rtc";
+		};
+
+		gpio {
+			compatible = "ti,tps6594x-gpio";
+		};
+	};
+};
-- 
2.38.GIT


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

* [PATCH v3 7/7] arm64: dts: ti: k3-j721s2-common-proc-board: Add TPS6594x PMIC node
@ 2022-11-09  6:55   ` Matt Ranostay
  0 siblings, 0 replies; 42+ messages in thread
From: Matt Ranostay @ 2022-11-09  6:55 UTC (permalink / raw)
  To: brgl, lee, linus.walleij, kristo, alexandre.belloni, a.zummo,
	krzysztof.kozlowski+dt, robh, vigneshr
  Cc: linux-arm-kernel, devicetree, linux-rtc, linux-gpio, Matt Ranostay

Add TPS6594x PMIC, GPIO, and RTC definitions for j721s2 common processor
board device tree.

Signed-off-by: Matt Ranostay <mranostay@ti.com>
---
 .../boot/dts/ti/k3-j721s2-common-proc-board.dts | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/arch/arm64/boot/dts/ti/k3-j721s2-common-proc-board.dts b/arch/arm64/boot/dts/ti/k3-j721s2-common-proc-board.dts
index a7aa6cf08acd..918c0c8d02cf 100644
--- a/arch/arm64/boot/dts/ti/k3-j721s2-common-proc-board.dts
+++ b/arch/arm64/boot/dts/ti/k3-j721s2-common-proc-board.dts
@@ -309,3 +309,20 @@ &mcu_mcan1 {
 	pinctrl-0 = <&mcu_mcan1_pins_default>;
 	phys = <&transceiver2>;
 };
+
+&wkup_i2c0 {
+	status = "okay";
+	tps6594x: tps6594x@48 {
+		compatible = "ti,tps6594x";
+		reg = <0x48>;
+		ti,system-power-controller;
+
+		rtc {
+			compatible = "ti,tps6594x-rtc";
+		};
+
+		gpio {
+			compatible = "ti,tps6594x-gpio";
+		};
+	};
+};
-- 
2.38.GIT


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 1/7] Documentation: tps6594x: Add DT bindings for the TPS6594x PMIC
  2022-11-09  6:55   ` Matt Ranostay
@ 2022-11-09  8:46     ` Krzysztof Kozlowski
  -1 siblings, 0 replies; 42+ messages in thread
From: Krzysztof Kozlowski @ 2022-11-09  8:46 UTC (permalink / raw)
  To: Matt Ranostay, brgl, lee, linus.walleij, kristo,
	alexandre.belloni, a.zummo, krzysztof.kozlowski+dt, robh,
	vigneshr
  Cc: linux-arm-kernel, devicetree, linux-rtc, linux-gpio

On 09/11/2022 07:55, Matt Ranostay wrote:

Missing commit msg.

Use subject prefixes matching the subsystem (git log --oneline -- ...).

> Signed-off-by: Matt Ranostay <mranostay@ti.com>
> ---
>  .../devicetree/bindings/mfd/ti,tps6594x.yaml  | 67 +++++++++++++++++++
>  1 file changed, 67 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..be87f0037bf9
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/mfd/ti,tps6594x.yaml
> @@ -0,0 +1,67 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/mfd/ti,tps6594x.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: TPS6594x Power Management Integrated Circuit (PMIC)
> +
> +maintainers:
> +  - Keerthy <j-keerthy@ti.com>
> +
> +properties:
> +  compatible:
> +    contains:

Drop contains.

> +      enum:
> +        - ti,tps6594x

No wildcards in compatibles.

> +
> +  reg:
> +    const: 0x48
> +    description: I2C slave address

Drop description.

> +
> +  ti,system-power-controller:
> +    type: boolean
> +    description: PMIC is controlling the system power.
> +
> +  rtc:
> +    type: object
> +    $ref: /schemas/rtc/rtc.yaml#
> +    unevaluatedProperties: false
> +    properties:
> +      compatible:
> +        const: ti,tps6594x-rtc

No wildcards in compatibles.

> +
> +  gpio:
> +    type: object
> +    unevaluatedProperties: false
> +    properties:
> +      compatible:
> +        const: ti,tps6594x-gpio

No wildcards in compatibles.

> +
> +additionalProperties: false
> +
> +required:
> +  - compatible

> +...

Best regards,
Krzysztof


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

* Re: [PATCH v3 1/7] Documentation: tps6594x: Add DT bindings for the TPS6594x PMIC
@ 2022-11-09  8:46     ` Krzysztof Kozlowski
  0 siblings, 0 replies; 42+ messages in thread
From: Krzysztof Kozlowski @ 2022-11-09  8:46 UTC (permalink / raw)
  To: Matt Ranostay, brgl, lee, linus.walleij, kristo,
	alexandre.belloni, a.zummo, krzysztof.kozlowski+dt, robh,
	vigneshr
  Cc: linux-arm-kernel, devicetree, linux-rtc, linux-gpio

On 09/11/2022 07:55, Matt Ranostay wrote:

Missing commit msg.

Use subject prefixes matching the subsystem (git log --oneline -- ...).

> Signed-off-by: Matt Ranostay <mranostay@ti.com>
> ---
>  .../devicetree/bindings/mfd/ti,tps6594x.yaml  | 67 +++++++++++++++++++
>  1 file changed, 67 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..be87f0037bf9
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/mfd/ti,tps6594x.yaml
> @@ -0,0 +1,67 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/mfd/ti,tps6594x.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: TPS6594x Power Management Integrated Circuit (PMIC)
> +
> +maintainers:
> +  - Keerthy <j-keerthy@ti.com>
> +
> +properties:
> +  compatible:
> +    contains:

Drop contains.

> +      enum:
> +        - ti,tps6594x

No wildcards in compatibles.

> +
> +  reg:
> +    const: 0x48
> +    description: I2C slave address

Drop description.

> +
> +  ti,system-power-controller:
> +    type: boolean
> +    description: PMIC is controlling the system power.
> +
> +  rtc:
> +    type: object
> +    $ref: /schemas/rtc/rtc.yaml#
> +    unevaluatedProperties: false
> +    properties:
> +      compatible:
> +        const: ti,tps6594x-rtc

No wildcards in compatibles.

> +
> +  gpio:
> +    type: object
> +    unevaluatedProperties: false
> +    properties:
> +      compatible:
> +        const: ti,tps6594x-gpio

No wildcards in compatibles.

> +
> +additionalProperties: false
> +
> +required:
> +  - compatible

> +...

Best regards,
Krzysztof


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 3/7] rtc: rtc-tps6594x: Add support for TPS6594X PMIC RTC
  2022-11-09  6:55   ` Matt Ranostay
@ 2022-11-09  8:49     ` Krzysztof Kozlowski
  -1 siblings, 0 replies; 42+ messages in thread
From: Krzysztof Kozlowski @ 2022-11-09  8:49 UTC (permalink / raw)
  To: Matt Ranostay, brgl, lee, linus.walleij, kristo,
	alexandre.belloni, a.zummo, krzysztof.kozlowski+dt, robh,
	vigneshr
  Cc: linux-arm-kernel, devicetree, linux-rtc, linux-gpio, Keerthy

On 09/11/2022 07:55, Matt Ranostay wrote:
> 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 35298c651730..0adb2c2570b8 100644
> --- a/drivers/rtc/Kconfig
> +++ b/drivers/rtc/Kconfig
> @@ -588,6 +588,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

Perhaps: || COMPILE_TEST
(and test it)

> +	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.
> +

(...)

> +
> +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);

That's not Linux coding style. Line is too long - wrapping is at 80.
sizeof(*), not struct.

> +	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 dev_err_probe


Best regards,
Krzysztof


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

* Re: [PATCH v3 3/7] rtc: rtc-tps6594x: Add support for TPS6594X PMIC RTC
@ 2022-11-09  8:49     ` Krzysztof Kozlowski
  0 siblings, 0 replies; 42+ messages in thread
From: Krzysztof Kozlowski @ 2022-11-09  8:49 UTC (permalink / raw)
  To: Matt Ranostay, brgl, lee, linus.walleij, kristo,
	alexandre.belloni, a.zummo, krzysztof.kozlowski+dt, robh,
	vigneshr
  Cc: linux-arm-kernel, devicetree, linux-rtc, linux-gpio, Keerthy

On 09/11/2022 07:55, Matt Ranostay wrote:
> 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 35298c651730..0adb2c2570b8 100644
> --- a/drivers/rtc/Kconfig
> +++ b/drivers/rtc/Kconfig
> @@ -588,6 +588,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

Perhaps: || COMPILE_TEST
(and test it)

> +	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.
> +

(...)

> +
> +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);

That's not Linux coding style. Line is too long - wrapping is at 80.
sizeof(*), not struct.

> +	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 dev_err_probe


Best regards,
Krzysztof


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 4/7] gpio: tps6594x: add GPIO support for TPS6594x PMIC
  2022-11-09  6:55   ` Matt Ranostay
@ 2022-11-09  8:50     ` Krzysztof Kozlowski
  -1 siblings, 0 replies; 42+ messages in thread
From: Krzysztof Kozlowski @ 2022-11-09  8:50 UTC (permalink / raw)
  To: Matt Ranostay, brgl, lee, linus.walleij, kristo,
	alexandre.belloni, a.zummo, krzysztof.kozlowski+dt, robh,
	vigneshr
  Cc: linux-arm-kernel, devicetree, linux-rtc, linux-gpio, Keerthy

On 09/11/2022 07:55, Matt Ranostay wrote:
> Add support for TPS6594X PMICs GPIO interface that has 11 that can be
> configured as input or outputs.
> 
> Tested-by: Keerthy <j-keerthy@ti.com>
> Signed-off-by: Matt Ranostay <mranostay@ti.com>
> ---
>  drivers/gpio/Kconfig         |   7 ++
>  drivers/gpio/Makefile        |   1 +
>  drivers/gpio/gpio-tps6594x.c | 142 +++++++++++++++++++++++++++++++++++
>  include/linux/mfd/tps6594x.h |   6 ++
>  4 files changed, 156 insertions(+)
>  create mode 100644 drivers/gpio/gpio-tps6594x.c
> 
> diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
> index 8c756cb29214..0225e6bddf0a 100644
> --- a/drivers/gpio/Kconfig
> +++ b/drivers/gpio/Kconfig
> @@ -1405,6 +1405,13 @@ config GPIO_TPS65912
>  	help
>  	  This driver supports TPS65912 GPIO chip.
>  
> +config GPIO_TPS6594X
> +	tristate "TI TPS6594X GPIO driver"
> +	depends on MFD_TPS6594X

Maybe || COMPILE_TEST?

> +	help
> +	  Select this option to enable GPIO driver for the TPS6954X
> +	  PMIC chip family. There are 11 GPIOs that can be configured.
> +

(...)

> +
> +static int tps6594x_gpio_probe(struct platform_device *pdev)
> +{
> +	struct tps6594x *tps = dev_get_drvdata(pdev->dev.parent);
> +	struct tps6594x_gpio *gpio;
> +
> +	gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL);

and here you did it correctly... I don't get why your two patches differ.

> +	if (!gpio)
> +		return -ENOMEM;
> +
> +	gpio->tps = dev_get_drvdata(pdev->dev.parent);
> +	gpio->gpio_chip = template_chip;
> +	gpio->gpio_chip.parent = tps->dev;
> +
> +	return devm_gpiochip_add_data(&pdev->dev, &gpio->gpio_chip, gpio);
> +}
> +
> +static const struct of_device_id of_tps6594x_gpio_match[] = {
> +	{ .compatible = "ti,tps6594x-gpio", },
> +	{},
> +};
> +MODULE_DEVICE_TABLE(of, of_tps6594x_gpio_match);
> +
> +static struct platform_driver tps6594x_gpio_driver = {
> +	.driver = {
> +		.name = "tps6594x-gpio",
> +		.of_match_table = of_match_ptr(of_tps6594x_gpio_match),

Drop of_match_ptr(). It comes with maybe_unused, which you do not have here.

Best regards,
Krzysztof


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

* Re: [PATCH v3 4/7] gpio: tps6594x: add GPIO support for TPS6594x PMIC
@ 2022-11-09  8:50     ` Krzysztof Kozlowski
  0 siblings, 0 replies; 42+ messages in thread
From: Krzysztof Kozlowski @ 2022-11-09  8:50 UTC (permalink / raw)
  To: Matt Ranostay, brgl, lee, linus.walleij, kristo,
	alexandre.belloni, a.zummo, krzysztof.kozlowski+dt, robh,
	vigneshr
  Cc: linux-arm-kernel, devicetree, linux-rtc, linux-gpio, Keerthy

On 09/11/2022 07:55, Matt Ranostay wrote:
> Add support for TPS6594X PMICs GPIO interface that has 11 that can be
> configured as input or outputs.
> 
> Tested-by: Keerthy <j-keerthy@ti.com>
> Signed-off-by: Matt Ranostay <mranostay@ti.com>
> ---
>  drivers/gpio/Kconfig         |   7 ++
>  drivers/gpio/Makefile        |   1 +
>  drivers/gpio/gpio-tps6594x.c | 142 +++++++++++++++++++++++++++++++++++
>  include/linux/mfd/tps6594x.h |   6 ++
>  4 files changed, 156 insertions(+)
>  create mode 100644 drivers/gpio/gpio-tps6594x.c
> 
> diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
> index 8c756cb29214..0225e6bddf0a 100644
> --- a/drivers/gpio/Kconfig
> +++ b/drivers/gpio/Kconfig
> @@ -1405,6 +1405,13 @@ config GPIO_TPS65912
>  	help
>  	  This driver supports TPS65912 GPIO chip.
>  
> +config GPIO_TPS6594X
> +	tristate "TI TPS6594X GPIO driver"
> +	depends on MFD_TPS6594X

Maybe || COMPILE_TEST?

> +	help
> +	  Select this option to enable GPIO driver for the TPS6954X
> +	  PMIC chip family. There are 11 GPIOs that can be configured.
> +

(...)

> +
> +static int tps6594x_gpio_probe(struct platform_device *pdev)
> +{
> +	struct tps6594x *tps = dev_get_drvdata(pdev->dev.parent);
> +	struct tps6594x_gpio *gpio;
> +
> +	gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL);

and here you did it correctly... I don't get why your two patches differ.

> +	if (!gpio)
> +		return -ENOMEM;
> +
> +	gpio->tps = dev_get_drvdata(pdev->dev.parent);
> +	gpio->gpio_chip = template_chip;
> +	gpio->gpio_chip.parent = tps->dev;
> +
> +	return devm_gpiochip_add_data(&pdev->dev, &gpio->gpio_chip, gpio);
> +}
> +
> +static const struct of_device_id of_tps6594x_gpio_match[] = {
> +	{ .compatible = "ti,tps6594x-gpio", },
> +	{},
> +};
> +MODULE_DEVICE_TABLE(of, of_tps6594x_gpio_match);
> +
> +static struct platform_driver tps6594x_gpio_driver = {
> +	.driver = {
> +		.name = "tps6594x-gpio",
> +		.of_match_table = of_match_ptr(of_tps6594x_gpio_match),

Drop of_match_ptr(). It comes with maybe_unused, which you do not have here.

Best regards,
Krzysztof


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 2/7] MFD: TPS6594x: Add new PMIC device driver for TPS6594x chips
  2022-11-09  6:55   ` Matt Ranostay
@ 2022-11-09  8:52     ` Krzysztof Kozlowski
  -1 siblings, 0 replies; 42+ messages in thread
From: Krzysztof Kozlowski @ 2022-11-09  8:52 UTC (permalink / raw)
  To: Matt Ranostay, brgl, lee, linus.walleij, kristo,
	alexandre.belloni, a.zummo, krzysztof.kozlowski+dt, robh,
	vigneshr
  Cc: linux-arm-kernel, devicetree, linux-rtc, linux-gpio, Keerthy

On 09/11/2022 07:55, Matt Ranostay wrote:
> From: Keerthy <j-keerthy@ti.com>
> 

Use subject prefixes matching the subsystem (git log --oneline -- ...).

> The TPS6594x chip is a PMIC, and contains the following components:
> 
> - 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       | 120 +++++++++++++++++++++++++++++++++++
>  include/linux/mfd/tps6594x.h |  84 ++++++++++++++++++++++++
>  4 files changed, 219 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 6e920442366c..9a6dc6b69058 100644
> --- a/drivers/mfd/Kconfig
> +++ b/drivers/mfd/Kconfig
> @@ -1596,6 +1596,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 && OF
> +	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 tps6594x.
> +
>  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 4dd479212b3a..51d7bfcd0a27 100644
> --- a/drivers/mfd/Makefile
> +++ b/drivers/mfd/Makefile
> @@ -101,6 +101,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..0de7946b6b8b
> --- /dev/null
> +++ b/drivers/mfd/tps6594x.c
> @@ -0,0 +1,120 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Driver for tps6594x PMIC chips
> + *
> + * Copyright (C) 2022 Texas Instruments Incorporated - https://www.ti.com/
> + * Author: Keerthy <j-keerthy@ti.com>
> + */
> +
> +#include <linux/of.h>
> +#include <linux/of_device.h>
> +#include <linux/mfd/core.h>
> +#include <linux/mfd/tps6594x.h>
> +#include <linux/module.h>
> +#include <linux/i2c.h>
> +#include <linux/regmap.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-gpio" },
> +	{ .name = "tps6594x-rtc" },

You have compatibles for children, so use them.

> +};
> +
> +static struct tps6594x *tps;
> +
> +static void tps6594x_power_off(void)
> +{
> +	regmap_write(tps->regmap, TPS6594X_FSM_NSLEEP_TRIGGERS,
> +		TPS6594X_FSM_NSLEEP_NSLEEP1B | TPS6594X_FSM_NSLEEP_NSLEEP2B);
> +
> +	regmap_write(tps->regmap, TPS6594X_INT_STARTUP,
> +		TPS6594X_INT_STARTUP_NPWRON_START_INT |
> +		TPS6594X_INT_STARTUP_ENABLE_INT | TPS6594X_INT_STARTUP_RTC_INT |
> +		TPS6594X_INT_STARTUP_SOFT_REBOOT_INT);
> +
> +	regmap_write(tps->regmap, TPS6594X_INT_MISC,
> +		TPS6594X_INT_MISC_BIST_PASS_INT |
> +		TPS6594X_INT_MISC_EXT_CLK_INT | TPS6594X_INT_MISC_TWARN_INT);
> +
> +	regmap_write(tps->regmap, TPS6594X_CONFIG_1,
> +		TPS6594X_CONFIG_NSLEEP1_MASK | TPS6594X_CONFIG_NSLEEP2_MASK);
> +
> +	regmap_write(tps->regmap, TPS6594X_FSM_I2C_TRIGGERS,
> +		TPS6594X_FSM_I2C_TRIGGERS_I2C0);
> +}
> +
> +static int tps6594x_probe(struct i2c_client *client)
> +{
> +	struct tps6594x *ddata;
> +	struct device_node *node = client->dev.of_node;
> +	unsigned int otpid;
> +	int ret;
> +
> +	ddata = devm_kzalloc(&client->dev, sizeof(*ddata), GFP_KERNEL);
> +	if (!ddata)
> +		return -ENOMEM;
> +
> +	ddata->dev = &client->dev;
> +
> +	ddata->regmap = devm_regmap_init_i2c(client, &tps6594x_regmap_config);
> +	if (IS_ERR(ddata->regmap)) {
> +		ret = PTR_ERR(ddata->regmap);
> +		dev_err(ddata->dev,
> +			"Failed to initialize register map: %d\n", ret);
> +		return ret;

return dev_err_probe

> +	}
> +
> +	ret = regmap_read(ddata->regmap, TPS6594X_REG_DEV_REV, &otpid);
> +	if (ret) {
> +		dev_err(ddata->dev, "Failed to read OTP ID\n");
> +		return ret;

return dev_err_probe

> +	}
> +
> +	ddata->rev = otpid;
> +	i2c_set_clientdata(client, ddata);
> +
> +	ret = mfd_add_devices(ddata->dev, PLATFORM_DEVID_AUTO, tps6594x_cells,
> +			      ARRAY_SIZE(tps6594x_cells), NULL, 0, NULL);
> +	if (ret) {
> +		dev_err(ddata->dev, "Failed to register cells\n");
> +		return ret;

return dev_err_probe

> +	}
> +
> +	tps = ddata;
> +
> +	if (of_property_read_bool(node, "ti,system-power-controller"))
> +		pm_power_off = tps6594x_power_off;
> +
> +	return 0;
> +}

Best regards,
Krzysztof


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

* Re: [PATCH v3 2/7] MFD: TPS6594x: Add new PMIC device driver for TPS6594x chips
@ 2022-11-09  8:52     ` Krzysztof Kozlowski
  0 siblings, 0 replies; 42+ messages in thread
From: Krzysztof Kozlowski @ 2022-11-09  8:52 UTC (permalink / raw)
  To: Matt Ranostay, brgl, lee, linus.walleij, kristo,
	alexandre.belloni, a.zummo, krzysztof.kozlowski+dt, robh,
	vigneshr
  Cc: linux-arm-kernel, devicetree, linux-rtc, linux-gpio, Keerthy

On 09/11/2022 07:55, Matt Ranostay wrote:
> From: Keerthy <j-keerthy@ti.com>
> 

Use subject prefixes matching the subsystem (git log --oneline -- ...).

> The TPS6594x chip is a PMIC, and contains the following components:
> 
> - 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       | 120 +++++++++++++++++++++++++++++++++++
>  include/linux/mfd/tps6594x.h |  84 ++++++++++++++++++++++++
>  4 files changed, 219 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 6e920442366c..9a6dc6b69058 100644
> --- a/drivers/mfd/Kconfig
> +++ b/drivers/mfd/Kconfig
> @@ -1596,6 +1596,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 && OF
> +	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 tps6594x.
> +
>  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 4dd479212b3a..51d7bfcd0a27 100644
> --- a/drivers/mfd/Makefile
> +++ b/drivers/mfd/Makefile
> @@ -101,6 +101,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..0de7946b6b8b
> --- /dev/null
> +++ b/drivers/mfd/tps6594x.c
> @@ -0,0 +1,120 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Driver for tps6594x PMIC chips
> + *
> + * Copyright (C) 2022 Texas Instruments Incorporated - https://www.ti.com/
> + * Author: Keerthy <j-keerthy@ti.com>
> + */
> +
> +#include <linux/of.h>
> +#include <linux/of_device.h>
> +#include <linux/mfd/core.h>
> +#include <linux/mfd/tps6594x.h>
> +#include <linux/module.h>
> +#include <linux/i2c.h>
> +#include <linux/regmap.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-gpio" },
> +	{ .name = "tps6594x-rtc" },

You have compatibles for children, so use them.

> +};
> +
> +static struct tps6594x *tps;
> +
> +static void tps6594x_power_off(void)
> +{
> +	regmap_write(tps->regmap, TPS6594X_FSM_NSLEEP_TRIGGERS,
> +		TPS6594X_FSM_NSLEEP_NSLEEP1B | TPS6594X_FSM_NSLEEP_NSLEEP2B);
> +
> +	regmap_write(tps->regmap, TPS6594X_INT_STARTUP,
> +		TPS6594X_INT_STARTUP_NPWRON_START_INT |
> +		TPS6594X_INT_STARTUP_ENABLE_INT | TPS6594X_INT_STARTUP_RTC_INT |
> +		TPS6594X_INT_STARTUP_SOFT_REBOOT_INT);
> +
> +	regmap_write(tps->regmap, TPS6594X_INT_MISC,
> +		TPS6594X_INT_MISC_BIST_PASS_INT |
> +		TPS6594X_INT_MISC_EXT_CLK_INT | TPS6594X_INT_MISC_TWARN_INT);
> +
> +	regmap_write(tps->regmap, TPS6594X_CONFIG_1,
> +		TPS6594X_CONFIG_NSLEEP1_MASK | TPS6594X_CONFIG_NSLEEP2_MASK);
> +
> +	regmap_write(tps->regmap, TPS6594X_FSM_I2C_TRIGGERS,
> +		TPS6594X_FSM_I2C_TRIGGERS_I2C0);
> +}
> +
> +static int tps6594x_probe(struct i2c_client *client)
> +{
> +	struct tps6594x *ddata;
> +	struct device_node *node = client->dev.of_node;
> +	unsigned int otpid;
> +	int ret;
> +
> +	ddata = devm_kzalloc(&client->dev, sizeof(*ddata), GFP_KERNEL);
> +	if (!ddata)
> +		return -ENOMEM;
> +
> +	ddata->dev = &client->dev;
> +
> +	ddata->regmap = devm_regmap_init_i2c(client, &tps6594x_regmap_config);
> +	if (IS_ERR(ddata->regmap)) {
> +		ret = PTR_ERR(ddata->regmap);
> +		dev_err(ddata->dev,
> +			"Failed to initialize register map: %d\n", ret);
> +		return ret;

return dev_err_probe

> +	}
> +
> +	ret = regmap_read(ddata->regmap, TPS6594X_REG_DEV_REV, &otpid);
> +	if (ret) {
> +		dev_err(ddata->dev, "Failed to read OTP ID\n");
> +		return ret;

return dev_err_probe

> +	}
> +
> +	ddata->rev = otpid;
> +	i2c_set_clientdata(client, ddata);
> +
> +	ret = mfd_add_devices(ddata->dev, PLATFORM_DEVID_AUTO, tps6594x_cells,
> +			      ARRAY_SIZE(tps6594x_cells), NULL, 0, NULL);
> +	if (ret) {
> +		dev_err(ddata->dev, "Failed to register cells\n");
> +		return ret;

return dev_err_probe

> +	}
> +
> +	tps = ddata;
> +
> +	if (of_property_read_bool(node, "ti,system-power-controller"))
> +		pm_power_off = tps6594x_power_off;
> +
> +	return 0;
> +}

Best regards,
Krzysztof


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 5/7] arm64: dts: ti: k3-j7200-common-proc-board: Add TPS6594x PMIC node
  2022-11-09  6:55   ` Matt Ranostay
@ 2022-11-09  8:52     ` Krzysztof Kozlowski
  -1 siblings, 0 replies; 42+ messages in thread
From: Krzysztof Kozlowski @ 2022-11-09  8:52 UTC (permalink / raw)
  To: Matt Ranostay, brgl, lee, linus.walleij, kristo,
	alexandre.belloni, a.zummo, krzysztof.kozlowski+dt, robh,
	vigneshr
  Cc: linux-arm-kernel, devicetree, linux-rtc, linux-gpio, Keerthy,
	Matt Ranostay

On 09/11/2022 07:55, Matt Ranostay wrote:
> From: Keerthy <j-keerthy@ti.com>
> 
> Add TPS6594x PMIC, GPIO, and RTC definitions for J7200 common processor
> board device tree.
> 
> Signed-off-by: Keerthy <j-keerthy@ti.com>
> Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
> ---
>  .../boot/dts/ti/k3-j7200-common-proc-board.dts  | 17 +++++++++++++++++
>  1 file changed, 17 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 6240856e4863..9514751739fe 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
> @@ -333,3 +333,20 @@ &pcie1_ep {
>  	num-lanes = <2>;
>  	status = "disabled";
>  };
> +
> +&wkup_i2c0 {
> +	status = "okay";
> +	tps6594x: tps6594x@48 {

Node names should be generic.
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation


Best regards,
Krzysztof


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

* Re: [PATCH v3 5/7] arm64: dts: ti: k3-j7200-common-proc-board: Add TPS6594x PMIC node
@ 2022-11-09  8:52     ` Krzysztof Kozlowski
  0 siblings, 0 replies; 42+ messages in thread
From: Krzysztof Kozlowski @ 2022-11-09  8:52 UTC (permalink / raw)
  To: Matt Ranostay, brgl, lee, linus.walleij, kristo,
	alexandre.belloni, a.zummo, krzysztof.kozlowski+dt, robh,
	vigneshr
  Cc: linux-arm-kernel, devicetree, linux-rtc, linux-gpio, Keerthy,
	Matt Ranostay

On 09/11/2022 07:55, Matt Ranostay wrote:
> From: Keerthy <j-keerthy@ti.com>
> 
> Add TPS6594x PMIC, GPIO, and RTC definitions for J7200 common processor
> board device tree.
> 
> Signed-off-by: Keerthy <j-keerthy@ti.com>
> Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
> ---
>  .../boot/dts/ti/k3-j7200-common-proc-board.dts  | 17 +++++++++++++++++
>  1 file changed, 17 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 6240856e4863..9514751739fe 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
> @@ -333,3 +333,20 @@ &pcie1_ep {
>  	num-lanes = <2>;
>  	status = "disabled";
>  };
> +
> +&wkup_i2c0 {
> +	status = "okay";
> +	tps6594x: tps6594x@48 {

Node names should be generic.
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation


Best regards,
Krzysztof


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 6/7] arm64: dts: ti: k3-j721e-common-proc-board: Add TPS6594x PMIC node
  2022-11-09  6:55   ` Matt Ranostay
@ 2022-11-09  8:52     ` Krzysztof Kozlowski
  -1 siblings, 0 replies; 42+ messages in thread
From: Krzysztof Kozlowski @ 2022-11-09  8:52 UTC (permalink / raw)
  To: Matt Ranostay, brgl, lee, linus.walleij, kristo,
	alexandre.belloni, a.zummo, krzysztof.kozlowski+dt, robh,
	vigneshr
  Cc: linux-arm-kernel, devicetree, linux-rtc, linux-gpio

On 09/11/2022 07:55, Matt Ranostay wrote:
> Add TPS6594x PMIC, GPIO, and RTC definitions for J721E common processor
> board device tree.
> 
> Signed-off-by: Matt Ranostay <mranostay@ti.com>
> ---
>  .../boot/dts/ti/k3-j721e-common-proc-board.dts  | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/arch/arm64/boot/dts/ti/k3-j721e-common-proc-board.dts b/arch/arm64/boot/dts/ti/k3-j721e-common-proc-board.dts
> index 1861598f3bb4..93bc7433ab06 100644
> --- a/arch/arm64/boot/dts/ti/k3-j721e-common-proc-board.dts
> +++ b/arch/arm64/boot/dts/ti/k3-j721e-common-proc-board.dts
> @@ -904,3 +904,20 @@ &main_mcan2 {
>  	pinctrl-0 = <&main_mcan2_pins_default>;
>  	phys = <&transceiver4>;
>  };
> +
> +&wkup_i2c0 {
> +	status = "okay";
> +	tps6594x: tps6594x@48 {

Node names should be generic.
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation


Best regards,
Krzysztof


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

* Re: [PATCH v3 6/7] arm64: dts: ti: k3-j721e-common-proc-board: Add TPS6594x PMIC node
@ 2022-11-09  8:52     ` Krzysztof Kozlowski
  0 siblings, 0 replies; 42+ messages in thread
From: Krzysztof Kozlowski @ 2022-11-09  8:52 UTC (permalink / raw)
  To: Matt Ranostay, brgl, lee, linus.walleij, kristo,
	alexandre.belloni, a.zummo, krzysztof.kozlowski+dt, robh,
	vigneshr
  Cc: linux-arm-kernel, devicetree, linux-rtc, linux-gpio

On 09/11/2022 07:55, Matt Ranostay wrote:
> Add TPS6594x PMIC, GPIO, and RTC definitions for J721E common processor
> board device tree.
> 
> Signed-off-by: Matt Ranostay <mranostay@ti.com>
> ---
>  .../boot/dts/ti/k3-j721e-common-proc-board.dts  | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/arch/arm64/boot/dts/ti/k3-j721e-common-proc-board.dts b/arch/arm64/boot/dts/ti/k3-j721e-common-proc-board.dts
> index 1861598f3bb4..93bc7433ab06 100644
> --- a/arch/arm64/boot/dts/ti/k3-j721e-common-proc-board.dts
> +++ b/arch/arm64/boot/dts/ti/k3-j721e-common-proc-board.dts
> @@ -904,3 +904,20 @@ &main_mcan2 {
>  	pinctrl-0 = <&main_mcan2_pins_default>;
>  	phys = <&transceiver4>;
>  };
> +
> +&wkup_i2c0 {
> +	status = "okay";
> +	tps6594x: tps6594x@48 {

Node names should be generic.
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation


Best regards,
Krzysztof


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 7/7] arm64: dts: ti: k3-j721s2-common-proc-board: Add TPS6594x PMIC node
  2022-11-09  6:55   ` Matt Ranostay
@ 2022-11-09  8:52     ` Krzysztof Kozlowski
  -1 siblings, 0 replies; 42+ messages in thread
From: Krzysztof Kozlowski @ 2022-11-09  8:52 UTC (permalink / raw)
  To: Matt Ranostay, brgl, lee, linus.walleij, kristo,
	alexandre.belloni, a.zummo, krzysztof.kozlowski+dt, robh,
	vigneshr
  Cc: linux-arm-kernel, devicetree, linux-rtc, linux-gpio

On 09/11/2022 07:55, Matt Ranostay wrote:
> Add TPS6594x PMIC, GPIO, and RTC definitions for j721s2 common processor
> board device tree.
> 
> Signed-off-by: Matt Ranostay <mranostay@ti.com>
> ---
>  .../boot/dts/ti/k3-j721s2-common-proc-board.dts | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/arch/arm64/boot/dts/ti/k3-j721s2-common-proc-board.dts b/arch/arm64/boot/dts/ti/k3-j721s2-common-proc-board.dts
> index a7aa6cf08acd..918c0c8d02cf 100644
> --- a/arch/arm64/boot/dts/ti/k3-j721s2-common-proc-board.dts
> +++ b/arch/arm64/boot/dts/ti/k3-j721s2-common-proc-board.dts
> @@ -309,3 +309,20 @@ &mcu_mcan1 {
>  	pinctrl-0 = <&mcu_mcan1_pins_default>;
>  	phys = <&transceiver2>;
>  };
> +
> +&wkup_i2c0 {
> +	status = "okay";
> +	tps6594x: tps6594x@48 {
> +		compatible = "ti,tps6594x";

Node names should be generic.
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation

Best regards,
Krzysztof


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

* Re: [PATCH v3 7/7] arm64: dts: ti: k3-j721s2-common-proc-board: Add TPS6594x PMIC node
@ 2022-11-09  8:52     ` Krzysztof Kozlowski
  0 siblings, 0 replies; 42+ messages in thread
From: Krzysztof Kozlowski @ 2022-11-09  8:52 UTC (permalink / raw)
  To: Matt Ranostay, brgl, lee, linus.walleij, kristo,
	alexandre.belloni, a.zummo, krzysztof.kozlowski+dt, robh,
	vigneshr
  Cc: linux-arm-kernel, devicetree, linux-rtc, linux-gpio

On 09/11/2022 07:55, Matt Ranostay wrote:
> Add TPS6594x PMIC, GPIO, and RTC definitions for j721s2 common processor
> board device tree.
> 
> Signed-off-by: Matt Ranostay <mranostay@ti.com>
> ---
>  .../boot/dts/ti/k3-j721s2-common-proc-board.dts | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/arch/arm64/boot/dts/ti/k3-j721s2-common-proc-board.dts b/arch/arm64/boot/dts/ti/k3-j721s2-common-proc-board.dts
> index a7aa6cf08acd..918c0c8d02cf 100644
> --- a/arch/arm64/boot/dts/ti/k3-j721s2-common-proc-board.dts
> +++ b/arch/arm64/boot/dts/ti/k3-j721s2-common-proc-board.dts
> @@ -309,3 +309,20 @@ &mcu_mcan1 {
>  	pinctrl-0 = <&mcu_mcan1_pins_default>;
>  	phys = <&transceiver2>;
>  };
> +
> +&wkup_i2c0 {
> +	status = "okay";
> +	tps6594x: tps6594x@48 {
> +		compatible = "ti,tps6594x";

Node names should be generic.
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation

Best regards,
Krzysztof


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 4/7] gpio: tps6594x: add GPIO support for TPS6594x PMIC
  2022-11-09  6:55   ` Matt Ranostay
@ 2022-11-09  9:59     ` Linus Walleij
  -1 siblings, 0 replies; 42+ messages in thread
From: Linus Walleij @ 2022-11-09  9:59 UTC (permalink / raw)
  To: Matt Ranostay
  Cc: brgl, lee, kristo, alexandre.belloni, a.zummo,
	krzysztof.kozlowski+dt, robh, vigneshr, linux-arm-kernel,
	devicetree, linux-rtc, linux-gpio, Keerthy

On Wed, Nov 9, 2022 at 7:56 AM Matt Ranostay <mranostay@ti.com> wrote:

> Add support for TPS6594X PMICs GPIO interface that has 11 that can be
> configured as input or outputs.
>
> Tested-by: Keerthy <j-keerthy@ti.com>
> Signed-off-by: Matt Ranostay <mranostay@ti.com>

(...)
> +config GPIO_TPS6594X
> +       tristate "TI TPS6594X GPIO driver"
> +       depends on MFD_TPS6594X
> +       help
> +         Select this option to enable GPIO driver for the TPS6954X
> +         PMIC chip family. There are 11 GPIOs that can be configured.

select GPIO_REGMAP

This driver is an archetypical example of a driver that can make great
use of GPIO_REGMAP helpers, so rewrite it to use them.
Look in drivers/gpio/gpio-sl28cpld.c for an example.

Yours,
Linus Walleij

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

* Re: [PATCH v3 4/7] gpio: tps6594x: add GPIO support for TPS6594x PMIC
@ 2022-11-09  9:59     ` Linus Walleij
  0 siblings, 0 replies; 42+ messages in thread
From: Linus Walleij @ 2022-11-09  9:59 UTC (permalink / raw)
  To: Matt Ranostay
  Cc: brgl, lee, kristo, alexandre.belloni, a.zummo,
	krzysztof.kozlowski+dt, robh, vigneshr, linux-arm-kernel,
	devicetree, linux-rtc, linux-gpio, Keerthy

On Wed, Nov 9, 2022 at 7:56 AM Matt Ranostay <mranostay@ti.com> wrote:

> Add support for TPS6594X PMICs GPIO interface that has 11 that can be
> configured as input or outputs.
>
> Tested-by: Keerthy <j-keerthy@ti.com>
> Signed-off-by: Matt Ranostay <mranostay@ti.com>

(...)
> +config GPIO_TPS6594X
> +       tristate "TI TPS6594X GPIO driver"
> +       depends on MFD_TPS6594X
> +       help
> +         Select this option to enable GPIO driver for the TPS6954X
> +         PMIC chip family. There are 11 GPIOs that can be configured.

select GPIO_REGMAP

This driver is an archetypical example of a driver that can make great
use of GPIO_REGMAP helpers, so rewrite it to use them.
Look in drivers/gpio/gpio-sl28cpld.c for an example.

Yours,
Linus Walleij

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 4/7] gpio: tps6594x: add GPIO support for TPS6594x PMIC
  2022-11-09  9:59     ` Linus Walleij
@ 2022-11-10 10:12       ` Matt Ranostay
  -1 siblings, 0 replies; 42+ messages in thread
From: Matt Ranostay @ 2022-11-10 10:12 UTC (permalink / raw)
  To: Linus Walleij
  Cc: brgl, lee, kristo, alexandre.belloni, a.zummo,
	krzysztof.kozlowski+dt, robh, vigneshr, linux-arm-kernel,
	devicetree, linux-rtc, linux-gpio, Keerthy

On Wed, Nov 09, 2022 at 10:59:08AM +0100, Linus Walleij wrote:
> On Wed, Nov 9, 2022 at 7:56 AM Matt Ranostay <mranostay@ti.com> wrote:
> 
> > Add support for TPS6594X PMICs GPIO interface that has 11 that can be
> > configured as input or outputs.
> >
> > Tested-by: Keerthy <j-keerthy@ti.com>
> > Signed-off-by: Matt Ranostay <mranostay@ti.com>
> 
> (...)
> > +config GPIO_TPS6594X
> > +       tristate "TI TPS6594X GPIO driver"
> > +       depends on MFD_TPS6594X
> > +       help
> > +         Select this option to enable GPIO driver for the TPS6954X
> > +         PMIC chip family. There are 11 GPIOs that can be configured.
> 
> select GPIO_REGMAP
> 
> This driver is an archetypical example of a driver that can make great
> use of GPIO_REGMAP helpers, so rewrite it to use them.
> Look in drivers/gpio/gpio-sl28cpld.c for an example.

Linus,

Those helpers look great for this usecase on the surface but however I think there could be some issues.
For GPIO direction it isn't configured by a bitmap on a register(s) but by a bit on a range of
registers (with a register for each GPIOx).

For set/get values the gpio helper would work though.

- Matt

> 
> Yours,
> Linus Walleij

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

* Re: [PATCH v3 4/7] gpio: tps6594x: add GPIO support for TPS6594x PMIC
@ 2022-11-10 10:12       ` Matt Ranostay
  0 siblings, 0 replies; 42+ messages in thread
From: Matt Ranostay @ 2022-11-10 10:12 UTC (permalink / raw)
  To: Linus Walleij
  Cc: brgl, lee, kristo, alexandre.belloni, a.zummo,
	krzysztof.kozlowski+dt, robh, vigneshr, linux-arm-kernel,
	devicetree, linux-rtc, linux-gpio, Keerthy

On Wed, Nov 09, 2022 at 10:59:08AM +0100, Linus Walleij wrote:
> On Wed, Nov 9, 2022 at 7:56 AM Matt Ranostay <mranostay@ti.com> wrote:
> 
> > Add support for TPS6594X PMICs GPIO interface that has 11 that can be
> > configured as input or outputs.
> >
> > Tested-by: Keerthy <j-keerthy@ti.com>
> > Signed-off-by: Matt Ranostay <mranostay@ti.com>
> 
> (...)
> > +config GPIO_TPS6594X
> > +       tristate "TI TPS6594X GPIO driver"
> > +       depends on MFD_TPS6594X
> > +       help
> > +         Select this option to enable GPIO driver for the TPS6954X
> > +         PMIC chip family. There are 11 GPIOs that can be configured.
> 
> select GPIO_REGMAP
> 
> This driver is an archetypical example of a driver that can make great
> use of GPIO_REGMAP helpers, so rewrite it to use them.
> Look in drivers/gpio/gpio-sl28cpld.c for an example.

Linus,

Those helpers look great for this usecase on the surface but however I think there could be some issues.
For GPIO direction it isn't configured by a bitmap on a register(s) but by a bit on a range of
registers (with a register for each GPIOx).

For set/get values the gpio helper would work though.

- Matt

> 
> Yours,
> Linus Walleij

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 4/7] gpio: tps6594x: add GPIO support for TPS6594x PMIC
  2022-11-10 10:12       ` Matt Ranostay
@ 2022-11-10 10:15         ` Linus Walleij
  -1 siblings, 0 replies; 42+ messages in thread
From: Linus Walleij @ 2022-11-10 10:15 UTC (permalink / raw)
  To: Matt Ranostay, Michael Walle
  Cc: brgl, lee, kristo, alexandre.belloni, a.zummo,
	krzysztof.kozlowski+dt, robh, vigneshr, linux-arm-kernel,
	devicetree, linux-rtc, linux-gpio, Keerthy

On Thu, Nov 10, 2022 at 11:12 AM Matt Ranostay <mranostay@ti.com> wrote:
> On Wed, Nov 09, 2022 at 10:59:08AM +0100, Linus Walleij wrote:
> > On Wed, Nov 9, 2022 at 7:56 AM Matt Ranostay <mranostay@ti.com> wrote:
> >
> > > Add support for TPS6594X PMICs GPIO interface that has 11 that can be
> > > configured as input or outputs.
> > >
> > > Tested-by: Keerthy <j-keerthy@ti.com>
> > > Signed-off-by: Matt Ranostay <mranostay@ti.com>
> >
> > (...)
> > > +config GPIO_TPS6594X
> > > +       tristate "TI TPS6594X GPIO driver"
> > > +       depends on MFD_TPS6594X
> > > +       help
> > > +         Select this option to enable GPIO driver for the TPS6954X
> > > +         PMIC chip family. There are 11 GPIOs that can be configured.
> >
> > select GPIO_REGMAP
> >
> > This driver is an archetypical example of a driver that can make great
> > use of GPIO_REGMAP helpers, so rewrite it to use them.
> > Look in drivers/gpio/gpio-sl28cpld.c for an example.
>
> Linus,
>
> Those helpers look great for this usecase on the surface but however I think there could be some issues.
> For GPIO direction it isn't configured by a bitmap on a register(s) but by a bit on a range of
> registers (with a register for each GPIOx).
>
> For set/get values the gpio helper would work though.

Isn't is possible to just use parts of the GPIO_REGMAP
helpers? I thought it's designed like such.

Michael Walle will know what to do with your usecase, and
whether to use it or not, let's page him!

Yours,
Linus Walleij

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

* Re: [PATCH v3 4/7] gpio: tps6594x: add GPIO support for TPS6594x PMIC
@ 2022-11-10 10:15         ` Linus Walleij
  0 siblings, 0 replies; 42+ messages in thread
From: Linus Walleij @ 2022-11-10 10:15 UTC (permalink / raw)
  To: Matt Ranostay, Michael Walle
  Cc: brgl, lee, kristo, alexandre.belloni, a.zummo,
	krzysztof.kozlowski+dt, robh, vigneshr, linux-arm-kernel,
	devicetree, linux-rtc, linux-gpio, Keerthy

On Thu, Nov 10, 2022 at 11:12 AM Matt Ranostay <mranostay@ti.com> wrote:
> On Wed, Nov 09, 2022 at 10:59:08AM +0100, Linus Walleij wrote:
> > On Wed, Nov 9, 2022 at 7:56 AM Matt Ranostay <mranostay@ti.com> wrote:
> >
> > > Add support for TPS6594X PMICs GPIO interface that has 11 that can be
> > > configured as input or outputs.
> > >
> > > Tested-by: Keerthy <j-keerthy@ti.com>
> > > Signed-off-by: Matt Ranostay <mranostay@ti.com>
> >
> > (...)
> > > +config GPIO_TPS6594X
> > > +       tristate "TI TPS6594X GPIO driver"
> > > +       depends on MFD_TPS6594X
> > > +       help
> > > +         Select this option to enable GPIO driver for the TPS6954X
> > > +         PMIC chip family. There are 11 GPIOs that can be configured.
> >
> > select GPIO_REGMAP
> >
> > This driver is an archetypical example of a driver that can make great
> > use of GPIO_REGMAP helpers, so rewrite it to use them.
> > Look in drivers/gpio/gpio-sl28cpld.c for an example.
>
> Linus,
>
> Those helpers look great for this usecase on the surface but however I think there could be some issues.
> For GPIO direction it isn't configured by a bitmap on a register(s) but by a bit on a range of
> registers (with a register for each GPIOx).
>
> For set/get values the gpio helper would work though.

Isn't is possible to just use parts of the GPIO_REGMAP
helpers? I thought it's designed like such.

Michael Walle will know what to do with your usecase, and
whether to use it or not, let's page him!

Yours,
Linus Walleij

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 4/7] gpio: tps6594x: add GPIO support for TPS6594x PMIC
  2022-11-10 10:15         ` Linus Walleij
@ 2022-11-11  8:58           ` Matt Ranostay
  -1 siblings, 0 replies; 42+ messages in thread
From: Matt Ranostay @ 2022-11-11  8:58 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Michael Walle, brgl, lee, kristo, alexandre.belloni, a.zummo,
	krzysztof.kozlowski+dt, robh, vigneshr, linux-arm-kernel,
	devicetree, linux-rtc, linux-gpio, Keerthy

On Thu, Nov 10, 2022 at 11:15:22AM +0100, Linus Walleij wrote:
> On Thu, Nov 10, 2022 at 11:12 AM Matt Ranostay <mranostay@ti.com> wrote:
> > On Wed, Nov 09, 2022 at 10:59:08AM +0100, Linus Walleij wrote:
> > > On Wed, Nov 9, 2022 at 7:56 AM Matt Ranostay <mranostay@ti.com> wrote:
> > >
> > > > Add support for TPS6594X PMICs GPIO interface that has 11 that can be
> > > > configured as input or outputs.
> > > >
> > > > Tested-by: Keerthy <j-keerthy@ti.com>
> > > > Signed-off-by: Matt Ranostay <mranostay@ti.com>
> > >
> > > (...)
> > > > +config GPIO_TPS6594X
> > > > +       tristate "TI TPS6594X GPIO driver"
> > > > +       depends on MFD_TPS6594X
> > > > +       help
> > > > +         Select this option to enable GPIO driver for the TPS6954X
> > > > +         PMIC chip family. There are 11 GPIOs that can be configured.
> > >
> > > select GPIO_REGMAP
> > >
> > > This driver is an archetypical example of a driver that can make great
> > > use of GPIO_REGMAP helpers, so rewrite it to use them.
> > > Look in drivers/gpio/gpio-sl28cpld.c for an example.
> >
> > Linus,
> >
> > Those helpers look great for this usecase on the surface but however I think there could be some issues.
> > For GPIO direction it isn't configured by a bitmap on a register(s) but by a bit on a range of
> > registers (with a register for each GPIOx).
> >
> > For set/get values the gpio helper would work though.
> 
> Isn't is possible to just use parts of the GPIO_REGMAP
> helpers? I thought it's designed like such.
> 
> Michael Walle will know what to do with your usecase, and
> whether to use it or not, let's page him!
>

So after looking around a bit and digging into the helper code I found this
drivers/pinctrl/bcm/pinctrl-bcm63xx.c which has a example on how to override
the reg_mask_xlate function which could be used for changing the stride, and mask
based on the base address.

Currently have coded up using the gpio regmap helper. Will run through some testing
first and then submit for review.

- Matt

> Yours,
> Linus Walleij

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 4/7] gpio: tps6594x: add GPIO support for TPS6594x PMIC
@ 2022-11-11  8:58           ` Matt Ranostay
  0 siblings, 0 replies; 42+ messages in thread
From: Matt Ranostay @ 2022-11-11  8:58 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Michael Walle, brgl, lee, kristo, alexandre.belloni, a.zummo,
	krzysztof.kozlowski+dt, robh, vigneshr, linux-arm-kernel,
	devicetree, linux-rtc, linux-gpio, Keerthy

On Thu, Nov 10, 2022 at 11:15:22AM +0100, Linus Walleij wrote:
> On Thu, Nov 10, 2022 at 11:12 AM Matt Ranostay <mranostay@ti.com> wrote:
> > On Wed, Nov 09, 2022 at 10:59:08AM +0100, Linus Walleij wrote:
> > > On Wed, Nov 9, 2022 at 7:56 AM Matt Ranostay <mranostay@ti.com> wrote:
> > >
> > > > Add support for TPS6594X PMICs GPIO interface that has 11 that can be
> > > > configured as input or outputs.
> > > >
> > > > Tested-by: Keerthy <j-keerthy@ti.com>
> > > > Signed-off-by: Matt Ranostay <mranostay@ti.com>
> > >
> > > (...)
> > > > +config GPIO_TPS6594X
> > > > +       tristate "TI TPS6594X GPIO driver"
> > > > +       depends on MFD_TPS6594X
> > > > +       help
> > > > +         Select this option to enable GPIO driver for the TPS6954X
> > > > +         PMIC chip family. There are 11 GPIOs that can be configured.
> > >
> > > select GPIO_REGMAP
> > >
> > > This driver is an archetypical example of a driver that can make great
> > > use of GPIO_REGMAP helpers, so rewrite it to use them.
> > > Look in drivers/gpio/gpio-sl28cpld.c for an example.
> >
> > Linus,
> >
> > Those helpers look great for this usecase on the surface but however I think there could be some issues.
> > For GPIO direction it isn't configured by a bitmap on a register(s) but by a bit on a range of
> > registers (with a register for each GPIOx).
> >
> > For set/get values the gpio helper would work though.
> 
> Isn't is possible to just use parts of the GPIO_REGMAP
> helpers? I thought it's designed like such.
> 
> Michael Walle will know what to do with your usecase, and
> whether to use it or not, let's page him!
>

So after looking around a bit and digging into the helper code I found this
drivers/pinctrl/bcm/pinctrl-bcm63xx.c which has a example on how to override
the reg_mask_xlate function which could be used for changing the stride, and mask
based on the base address.

Currently have coded up using the gpio regmap helper. Will run through some testing
first and then submit for review.

- Matt

> Yours,
> Linus Walleij

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

* Re: [PATCH v3 3/7] rtc: rtc-tps6594x: Add support for TPS6594X PMIC RTC
  2022-11-09  6:55   ` Matt Ranostay
@ 2022-11-14 20:48     ` Alexandre Belloni
  -1 siblings, 0 replies; 42+ messages in thread
From: Alexandre Belloni @ 2022-11-14 20:48 UTC (permalink / raw)
  To: Matt Ranostay
  Cc: brgl, lee, linus.walleij, kristo, a.zummo,
	krzysztof.kozlowski+dt, robh, vigneshr, linux-arm-kernel,
	devicetree, linux-rtc, linux-gpio, Keerthy

Hello,

On 08/11/2022 22:55:42-0800, Matt Ranostay wrote:
> 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

Is this TODO actually useful? :)

> +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);

I would avoid these messages that are not actually actionable.

> +		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));

Maybe you should go for regmap_read_poll_timeout.

> +
> +	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;
> +	}

It doesn't make sense to start the RTC in probe as it is probably
already started and time is kept properly or it is not started and then
you can use this information in tps6594x_rtc_read_time as you know the
time is not correct.
I'd rather ensure it is started in tps6594x_rtc_set_time.

> +
> +	tps6594x_rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,

This is deprecated, please use devm_rtc_allocate_device() and
devm_rtc_register_device(). You also need to set the range properly.

> +				&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);

This message is useless as the core aloready pronts an error on
registration failure.

> +		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.38.GIT
> 

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

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

* Re: [PATCH v3 3/7] rtc: rtc-tps6594x: Add support for TPS6594X PMIC RTC
@ 2022-11-14 20:48     ` Alexandre Belloni
  0 siblings, 0 replies; 42+ messages in thread
From: Alexandre Belloni @ 2022-11-14 20:48 UTC (permalink / raw)
  To: Matt Ranostay
  Cc: brgl, lee, linus.walleij, kristo, a.zummo,
	krzysztof.kozlowski+dt, robh, vigneshr, linux-arm-kernel,
	devicetree, linux-rtc, linux-gpio, Keerthy

Hello,

On 08/11/2022 22:55:42-0800, Matt Ranostay wrote:
> 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

Is this TODO actually useful? :)

> +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);

I would avoid these messages that are not actually actionable.

> +		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));

Maybe you should go for regmap_read_poll_timeout.

> +
> +	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;
> +	}

It doesn't make sense to start the RTC in probe as it is probably
already started and time is kept properly or it is not started and then
you can use this information in tps6594x_rtc_read_time as you know the
time is not correct.
I'd rather ensure it is started in tps6594x_rtc_set_time.

> +
> +	tps6594x_rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,

This is deprecated, please use devm_rtc_allocate_device() and
devm_rtc_register_device(). You also need to set the range properly.

> +				&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);

This message is useless as the core aloready pronts an error on
registration failure.

> +		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.38.GIT
> 

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v3 4/7] gpio: tps6594x: add GPIO support for TPS6594x PMIC
  2022-11-11  8:58           ` Matt Ranostay
@ 2022-11-16  7:31             ` Michael Walle
  -1 siblings, 0 replies; 42+ messages in thread
From: Michael Walle @ 2022-11-16  7:31 UTC (permalink / raw)
  To: Matt Ranostay
  Cc: Linus Walleij, brgl, lee, kristo, alexandre.belloni, a.zummo,
	krzysztof.kozlowski+dt, robh, vigneshr, linux-arm-kernel,
	devicetree, linux-rtc, linux-gpio, Keerthy

Hi,

Am 2022-11-11 09:58, schrieb Matt Ranostay:
> On Thu, Nov 10, 2022 at 11:15:22AM +0100, Linus Walleij wrote:
>> On Thu, Nov 10, 2022 at 11:12 AM Matt Ranostay <mranostay@ti.com> 
>> wrote:
>> > On Wed, Nov 09, 2022 at 10:59:08AM +0100, Linus Walleij wrote:
>> > > On Wed, Nov 9, 2022 at 7:56 AM Matt Ranostay <mranostay@ti.com> wrote:
>> > >
>> > > > Add support for TPS6594X PMICs GPIO interface that has 11 that can be
>> > > > configured as input or outputs.
>> > > >
>> > > > Tested-by: Keerthy <j-keerthy@ti.com>
>> > > > Signed-off-by: Matt Ranostay <mranostay@ti.com>
>> > >
>> > > (...)
>> > > > +config GPIO_TPS6594X
>> > > > +       tristate "TI TPS6594X GPIO driver"
>> > > > +       depends on MFD_TPS6594X
>> > > > +       help
>> > > > +         Select this option to enable GPIO driver for the TPS6954X
>> > > > +         PMIC chip family. There are 11 GPIOs that can be configured.
>> > >
>> > > select GPIO_REGMAP
>> > >
>> > > This driver is an archetypical example of a driver that can make great
>> > > use of GPIO_REGMAP helpers, so rewrite it to use them.
>> > > Look in drivers/gpio/gpio-sl28cpld.c for an example.
>> >
>> > Linus,
>> >
>> > Those helpers look great for this usecase on the surface but however I think there could be some issues.
>> > For GPIO direction it isn't configured by a bitmap on a register(s) but by a bit on a range of
>> > registers (with a register for each GPIOx).

As long as there is only one register to be changed per pin/action,
.reg_mask_xlate should work, as you've already found out.

>> > For set/get values the gpio helper would work though.
>> 
>> Isn't is possible to just use parts of the GPIO_REGMAP
>> helpers? I thought it's designed like such.

No, you can't use them as they are kept private, along with
the needed struct gpio_regmap. Which was intentional back then
as it should be easier to change the implementation or add features
without its use being spread all over the gpio drivers.

We could change that though - or just add the needed feature to
gpio-regmap if it looks generic enough.

>> 
>> Michael Walle will know what to do with your usecase, and
>> whether to use it or not, let's page him!
>> 
> 
> So after looking around a bit and digging into the helper code I found 
> this
> drivers/pinctrl/bcm/pinctrl-bcm63xx.c which has a example on how to 
> override
> the reg_mask_xlate function which could be used for changing the
> stride, and mask
> based on the base address.
> 
> Currently have coded up using the gpio regmap helper. Will run through
> some testing
> first and then submit for review.

Sounds promising.

-michael

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

* Re: [PATCH v3 4/7] gpio: tps6594x: add GPIO support for TPS6594x PMIC
@ 2022-11-16  7:31             ` Michael Walle
  0 siblings, 0 replies; 42+ messages in thread
From: Michael Walle @ 2022-11-16  7:31 UTC (permalink / raw)
  To: Matt Ranostay
  Cc: Linus Walleij, brgl, lee, kristo, alexandre.belloni, a.zummo,
	krzysztof.kozlowski+dt, robh, vigneshr, linux-arm-kernel,
	devicetree, linux-rtc, linux-gpio, Keerthy

Hi,

Am 2022-11-11 09:58, schrieb Matt Ranostay:
> On Thu, Nov 10, 2022 at 11:15:22AM +0100, Linus Walleij wrote:
>> On Thu, Nov 10, 2022 at 11:12 AM Matt Ranostay <mranostay@ti.com> 
>> wrote:
>> > On Wed, Nov 09, 2022 at 10:59:08AM +0100, Linus Walleij wrote:
>> > > On Wed, Nov 9, 2022 at 7:56 AM Matt Ranostay <mranostay@ti.com> wrote:
>> > >
>> > > > Add support for TPS6594X PMICs GPIO interface that has 11 that can be
>> > > > configured as input or outputs.
>> > > >
>> > > > Tested-by: Keerthy <j-keerthy@ti.com>
>> > > > Signed-off-by: Matt Ranostay <mranostay@ti.com>
>> > >
>> > > (...)
>> > > > +config GPIO_TPS6594X
>> > > > +       tristate "TI TPS6594X GPIO driver"
>> > > > +       depends on MFD_TPS6594X
>> > > > +       help
>> > > > +         Select this option to enable GPIO driver for the TPS6954X
>> > > > +         PMIC chip family. There are 11 GPIOs that can be configured.
>> > >
>> > > select GPIO_REGMAP
>> > >
>> > > This driver is an archetypical example of a driver that can make great
>> > > use of GPIO_REGMAP helpers, so rewrite it to use them.
>> > > Look in drivers/gpio/gpio-sl28cpld.c for an example.
>> >
>> > Linus,
>> >
>> > Those helpers look great for this usecase on the surface but however I think there could be some issues.
>> > For GPIO direction it isn't configured by a bitmap on a register(s) but by a bit on a range of
>> > registers (with a register for each GPIOx).

As long as there is only one register to be changed per pin/action,
.reg_mask_xlate should work, as you've already found out.

>> > For set/get values the gpio helper would work though.
>> 
>> Isn't is possible to just use parts of the GPIO_REGMAP
>> helpers? I thought it's designed like such.

No, you can't use them as they are kept private, along with
the needed struct gpio_regmap. Which was intentional back then
as it should be easier to change the implementation or add features
without its use being spread all over the gpio drivers.

We could change that though - or just add the needed feature to
gpio-regmap if it looks generic enough.

>> 
>> Michael Walle will know what to do with your usecase, and
>> whether to use it or not, let's page him!
>> 
> 
> So after looking around a bit and digging into the helper code I found 
> this
> drivers/pinctrl/bcm/pinctrl-bcm63xx.c which has a example on how to 
> override
> the reg_mask_xlate function which could be used for changing the
> stride, and mask
> based on the base address.
> 
> Currently have coded up using the gpio regmap helper. Will run through
> some testing
> first and then submit for review.

Sounds promising.

-michael

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

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

Thread overview: 42+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-09  6:55 [PATCH v3 0/7] mfd: add tps6594x support for Jacinto platforms Matt Ranostay
2022-11-09  6:55 ` Matt Ranostay
2022-11-09  6:55 ` [PATCH v3 1/7] Documentation: tps6594x: Add DT bindings for the TPS6594x PMIC Matt Ranostay
2022-11-09  6:55   ` Matt Ranostay
2022-11-09  8:46   ` Krzysztof Kozlowski
2022-11-09  8:46     ` Krzysztof Kozlowski
2022-11-09  6:55 ` [PATCH v3 2/7] MFD: TPS6594x: Add new PMIC device driver for TPS6594x chips Matt Ranostay
2022-11-09  6:55   ` Matt Ranostay
2022-11-09  8:52   ` Krzysztof Kozlowski
2022-11-09  8:52     ` Krzysztof Kozlowski
2022-11-09  6:55 ` [PATCH v3 3/7] rtc: rtc-tps6594x: Add support for TPS6594X PMIC RTC Matt Ranostay
2022-11-09  6:55   ` Matt Ranostay
2022-11-09  8:49   ` Krzysztof Kozlowski
2022-11-09  8:49     ` Krzysztof Kozlowski
2022-11-14 20:48   ` Alexandre Belloni
2022-11-14 20:48     ` Alexandre Belloni
2022-11-09  6:55 ` [PATCH v3 4/7] gpio: tps6594x: add GPIO support for TPS6594x PMIC Matt Ranostay
2022-11-09  6:55   ` Matt Ranostay
2022-11-09  8:50   ` Krzysztof Kozlowski
2022-11-09  8:50     ` Krzysztof Kozlowski
2022-11-09  9:59   ` Linus Walleij
2022-11-09  9:59     ` Linus Walleij
2022-11-10 10:12     ` Matt Ranostay
2022-11-10 10:12       ` Matt Ranostay
2022-11-10 10:15       ` Linus Walleij
2022-11-10 10:15         ` Linus Walleij
2022-11-11  8:58         ` Matt Ranostay
2022-11-11  8:58           ` Matt Ranostay
2022-11-16  7:31           ` Michael Walle
2022-11-16  7:31             ` Michael Walle
2022-11-09  6:55 ` [PATCH v3 5/7] arm64: dts: ti: k3-j7200-common-proc-board: Add TPS6594x PMIC node Matt Ranostay
2022-11-09  6:55   ` Matt Ranostay
2022-11-09  8:52   ` Krzysztof Kozlowski
2022-11-09  8:52     ` Krzysztof Kozlowski
2022-11-09  6:55 ` [PATCH v3 6/7] arm64: dts: ti: k3-j721e-common-proc-board: " Matt Ranostay
2022-11-09  6:55   ` Matt Ranostay
2022-11-09  8:52   ` Krzysztof Kozlowski
2022-11-09  8:52     ` Krzysztof Kozlowski
2022-11-09  6:55 ` [PATCH v3 7/7] arm64: dts: ti: k3-j721s2-common-proc-board: " Matt Ranostay
2022-11-09  6:55   ` Matt Ranostay
2022-11-09  8:52   ` Krzysztof Kozlowski
2022-11-09  8:52     ` Krzysztof Kozlowski

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.