Skip to contentSkip to conversation

mfd: add tps6594 support for Jacinto platforms

PATCH In review Matt Ranostay 9 participants 16 messages Nov 23, 2022 – Jan 4, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v5 cover mfd: add tps6594 support for Jacinto platforms

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

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

Changes from v3:
* Refactoring gpio driver to use regmap gpio helpers
* Changing rtc driver to use more of device resource management
* Minor code changes related to error messages that aren't useful being dropped
* Dropped wildcard in device-tree compatible, and i2c device id
* Dropped device tree changes from the series; since these should be in their own series later

Changes from v4:
* Corrected commit messages for device tree documentation
* Added TPS6954 datasheet PDF to devicetree documentation
* Renamed all references, including filenames + configuration options, from tps6594x to tps6594 dropping the unneeded wildcard

Keerthy (2):
mfd: tps6594: Add support for TPS6594 PMIC devices
rtc: rtc-tps6594: Add support for TPS6594 PMIC RTC

Matt Ranostay (2):
dt-bindings: mfd: ti,tps6594: add TPS6594 PMIC support
gpio: gpio-tps6594: add GPIO support for TPS6594 PMIC

 .../devicetree/bindings/mfd/ti,tps6594.yaml   |  69 ++++++++
 drivers/gpio/Kconfig                          |   9 +
 drivers/gpio/Makefile                         |   1 +
 drivers/gpio/gpio-tps6594.c                   |  78 +++++++++
 drivers/mfd/Kconfig                           |  14 ++
 drivers/mfd/Makefile                          |   1 +
 drivers/mfd/tps6594.c                         | 113 +++++++++++++
 drivers/rtc/Kconfig                           |  10 ++
 drivers/rtc/Makefile                          |   1 +
 drivers/rtc/rtc-tps6594.c                     | 155 ++++++++++++++++++
 include/linux/mfd/tps6594.h                   |  88 ++++++++++
 11 files changed, 539 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/ti,tps6594.yaml
 create mode 100644 drivers/gpio/gpio-tps6594.c
 create mode 100644 drivers/mfd/tps6594.c
 create mode 100644 drivers/rtc/rtc-tps6594.c
 create mode 100644 include/linux/mfd/tps6594.h
Signature · 1 line
2.38.GIT
#1 lore raw

PATCH v5 1/4 dt-bindings: mfd: ti,tps6594: add TPS6594 PMIC support

Add documentation for the TPS6594 PMIC including its RTC and GPIO functionalities.

---
 .../devicetree/bindings/mfd/ti,tps6594.yaml   | 69 +++++++++++++++++++
 1 file changed, 69 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/ti,tps6594.yaml
Documentation/devicetree/bindings/mfd/ti,tps6594.yaml new file +69 -0
new file mode 100644
index 000000000000..0de0db87dbf7
@@ -0,0 +1,69 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/ti,tps6594.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: TPS6594 Power Management Integrated Circuit (PMIC)
+
+description: |
+  TPS6594 Power Management Integrated Circuit (PMIC)
+  https://www.ti.com/lit/ds/symlink/tps6594-q1.pdf
+
+maintainers:
+  - Keerthy <[email protected]>
+
+properties:
+  compatible:
+    enum:
+      - ti,tps6594
+
+  reg:
+    const: 0x48
+
+  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,tps6594-rtc
+
+  gpio:
+    type: object
+    unevaluatedProperties: false
+    properties:
+      compatible:
+        const: ti,tps6594-gpio
+
+additionalProperties: false
+
+required:
+  - compatible
+  - reg
+
+examples:
+  - |
+    i2c0 {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        pmic: pmic@48 {
+            compatible = "ti,tps6594";
+            reg = <0x48>;
+
+            rtc {
+                compatible = "ti,tps6594-rtc";
+            };
+
+            gpio {
+                compatible = "ti,tps6594-gpio";
+            };
+        };
+    };
+
+...
Signature · 1 line
2.38.GIT
Reviewed-by on v5 1/4
#2 lore raw

Re: [PATCH v5 1/4] dt-bindings: mfd: ti,tps6594: add TPS6594 PMIC support

Quoted 2 lines · Matt Ranostay

Add documentation for the TPS6594 PMIC including its RTC and GPIO functionalities.

#3 lore raw

Re: [PATCH v5 1/4] dt-bindings: mfd: ti,tps6594: add TPS6594 PMIC support

In reply to Matt Ranostay
Quoted 2 lines · Matt Ranostay

Add documentation for the TPS6594 PMIC including its RTC and GPIO functionalities.

Back in September I asked to use get_maintainers.pl to CC people. Can you please tell me, why you still prefer not to use it's output and instead use a bit different email addresses?

How many times same feedback should be given?

Quoted 63 lines
---
 .../devicetree/bindings/mfd/ti,tps6594.yaml   | 69 +++++++++++++++++++
 1 file changed, 69 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/ti,tps6594.yaml
Documentation/devicetree/bindings/mfd/ti,tps6594.yaml new file +50 -0
new file mode 100644
index 000000000000..0de0db87dbf7
@@ -0,0 +1,69 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/ti,tps6594.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: TPS6594 Power Management Integrated Circuit (PMIC)
+
+description: |
+  TPS6594 Power Management Integrated Circuit (PMIC)
+  https://www.ti.com/lit/ds/symlink/tps6594-q1.pdf
+
+maintainers:
+  - Keerthy <[email protected]>
+
+properties:
+  compatible:
+    enum:
+      - ti,tps6594
+
+  reg:
+    const: 0x48
+
+  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,tps6594-rtc
+
+  gpio:
+    type: object
+    unevaluatedProperties: false
+    properties:
+      compatible:
+        const: ti,tps6594-gpio
+
+additionalProperties: false
+
+required:
+  - compatible
+  - reg
+
+examples:
+  - |

Documentation/devicetree/bindings/mfd/ti,tps6594.yaml line 60

Quoted 10 lines
Documentation/devicetree/bindings/mfd/ti,tps6594.yaml new file +10 -0
+    i2c0 {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        pmic: pmic@48 {
+            compatible = "ti,tps6594";
+            reg = <0x48>;
+
+            rtc {
+                compatible = "ti,tps6594-rtc";

No resources? No properties? Usually such nodes are not useful at all. Rob pointed this some times in different cases, but I don't remember if we resolved it here.

Documentation/devicetree/bindings/mfd/ti,tps6594.yaml line 64

Quoted 4 lines
Documentation/devicetree/bindings/mfd/ti,tps6594.yaml new file +4 -0
+            };
+
+            gpio {
+                compatible = "ti,tps6594-gpio";

Same question.

Documentation/devicetree/bindings/mfd/ti,tps6594.yaml line 69

Quoted 5 lines
Documentation/devicetree/bindings/mfd/ti,tps6594.yaml new file +5 -0
+            };
+        };
+    };
+
+...

Best regards,
Krzysztof

maintainer
#4 lore raw

Re: [PATCH v5 1/4] dt-bindings: mfd: ti,tps6594: add TPS6594 PMIC support

In reply to Matt Ranostay
Quoted 16 lines · Matt Ranostay

Add documentation for the TPS6594 PMIC including its RTC and GPIO functionalities.

---
 .../devicetree/bindings/mfd/ti,tps6594.yaml   | 69 +++++++++++++++++++
 1 file changed, 69 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/ti,tps6594.yaml
Documentation/devicetree/bindings/mfd/ti,tps6594.yaml new file +1 -0
new file mode 100644
index 000000000000..0de0db87dbf7
@@ -0,0 +1,69 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)

Documentation/devicetree/bindings/mfd/ti,tps6594.yaml line 11

Quoted 10 lines
Documentation/devicetree/bindings/mfd/ti,tps6594.yaml new file +10 -0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/ti,tps6594.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: TPS6594 Power Management Integrated Circuit (PMIC)
+
+description: |
+  TPS6594 Power Management Integrated Circuit (PMIC)
+  https://www.ti.com/lit/ds/symlink/tps6594-q1.pdf

Normally a PMIC has some regulators...

Quoted 20 lines
Documentation/devicetree/bindings/mfd/ti,tps6594.yaml new file +20 -0
+
+maintainers:
+  - Keerthy <[email protected]>
+
+properties:
+  compatible:
+    enum:
+      - ti,tps6594
+
+  reg:
+    const: 0x48
+
+  ti,system-power-controller:
+    type: boolean
+    description: PMIC is controlling the system power.
+
+  rtc:
+    type: object
+    $ref: /schemas/rtc/rtc.yaml#
+    unevaluatedProperties: false

Documentation/devicetree/bindings/mfd/ti,tps6594.yaml line 41

Quoted 10 lines
Documentation/devicetree/bindings/mfd/ti,tps6594.yaml new file +10 -0
+    properties:
+      compatible:
+        const: ti,tps6594-rtc
+
+  gpio:
+    type: object
+    unevaluatedProperties: false
+    properties:
+      compatible:
+        const: ti,tps6594-gpio

GPIO, but not using the GPIO binding?

As Krzysztof pointed out, none of this needs child nodes. You have them just for convenience of instantiating Linux drivers.

Quoted 32 lines
Documentation/devicetree/bindings/mfd/ti,tps6594.yaml new file +28 -0
+
+additionalProperties: false
+
+required:
+  - compatible
+  - reg
+
+examples:
+  - |
+    i2c0 {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        pmic: pmic@48 {
+            compatible = "ti,tps6594";
+            reg = <0x48>;
+
+            rtc {
+                compatible = "ti,tps6594-rtc";
+            };
+
+            gpio {
+                compatible = "ti,tps6594-gpio";
+            };
+        };
+    };
+
+...
Signature · 1 line
2.38.GIT
#5 lore raw

PATCH v5 2/4 mfd: tps6594: Add support for TPS6594 PMIC devices

In reply to Matt Ranostay

From: Keerthy <[email protected]>

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

- GPIO controller
- RTC

---
 drivers/mfd/Kconfig         |  14 +++++
 drivers/mfd/Makefile        |   1 +
 drivers/mfd/tps6594.c       | 113 ++++++++++++++++++++++++++++++++++++
 include/linux/mfd/tps6594.h |  84 +++++++++++++++++++++++++++
 4 files changed, 212 insertions(+)
 create mode 100644 drivers/mfd/tps6594.c
 create mode 100644 include/linux/mfd/tps6594.h
drivers/mfd/Kconfig +14 -0
index 6653d03e0fe3..c54f2959a200 100644
@@ -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_TPS6594
+	tristate "TI TPS6594 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 TPS6594 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 tps6594.
+
 config MFD_TI_LP87565
 	tristate "TI LP87565 Power Management IC"
 	depends on I2C && OF
drivers/mfd/Makefile +1 -0
index 4dd479212b3a..b4fdfcc57831 100644
@@ -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_TPS6594)	+= tps6594.o
 obj-$(CONFIG_MENELAUS)		+= menelaus.o
 
 obj-$(CONFIG_TWL4030_CORE)	+= twl-core.o twl4030-irq.o twl6030-irq.o
drivers/mfd/tps6594.c new file +113 -0

113 lines not on this page · raw message

include/linux/mfd/tps6594.h new file +84 -0

84 lines not on this page · raw message

Signature · 1 line
2.38.GIT
maintainer
#7 lore raw

Re: [PATCH v5 2/4] mfd: tps6594: Add support for TPS6594 PMIC devices

In reply to Matt Ranostay
Quoted 66 lines · Matt Ranostay

From: Keerthy <[email protected]>

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

- GPIO controller
- RTC

---
 drivers/mfd/Kconfig         |  14 +++++
 drivers/mfd/Makefile        |   1 +
 drivers/mfd/tps6594.c       | 113 ++++++++++++++++++++++++++++++++++++
 include/linux/mfd/tps6594.h |  84 +++++++++++++++++++++++++++
 4 files changed, 212 insertions(+)
 create mode 100644 drivers/mfd/tps6594.c
 create mode 100644 include/linux/mfd/tps6594.h
drivers/mfd/Kconfig +14 -0
index 6653d03e0fe3..c54f2959a200 100644
@@ -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_TPS6594
+	tristate "TI TPS6594 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 TPS6594 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 tps6594.
+
 config MFD_TI_LP87565
 	tristate "TI LP87565 Power Management IC"
 	depends on I2C && OF
drivers/mfd/Makefile +1 -0
index 4dd479212b3a..b4fdfcc57831 100644
@@ -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_TPS6594)	+= tps6594.o
 obj-$(CONFIG_MENELAUS)		+= menelaus.o
 
 obj-$(CONFIG_TWL4030_CORE)	+= twl-core.o twl4030-irq.o twl6030-irq.o
drivers/mfd/tps6594.c new file +5 -0
new file mode 100644
index 000000000000..a7f80833e8fc
@@ -0,0 +1,113 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Driver for TPS6594 PMIC chips
+ *
+ * Copyright (C) 2022 Texas Instruments Incorporated - https://www.ti.com/

drivers/mfd/tps6594.c line 15

Quoted 10 lines
drivers/mfd/tps6594.c new file +10 -0
+ * Author: Keerthy <[email protected]>
+ */
+
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/mfd/core.h>
+#include <linux/mfd/tps6594.h>
+#include <linux/module.h>
+#include <linux/i2c.h>
+#include <linux/regmap.h>

Nit: Alphabetical.

Quoted 7 lines
drivers/mfd/tps6594.c new file +7 -0
+static const struct regmap_config tps6594_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.max_register = TPS6594_REG_MAX,
+};
+
+static const struct mfd_cell tps6594_cells[] = {

drivers/mfd/tps6594.c line 33

Quoted 10 lines
drivers/mfd/tps6594.c new file +10 -0
+	{ .name = "tps6594-gpio" },
+	{ .name = "tps6594-rtc" },
+};
+
+static struct tps6594 *tps;
+
+static void tps6594_power_off(void)
+{
+	regmap_write(tps->regmap, TPS6594_FSM_NSLEEP_TRIGGERS,
+		TPS6594_FSM_NSLEEP_NSLEEP1B | TPS6594_FSM_NSLEEP_NSLEEP2B);

Any chance we can align against the open parentheses?

Quoted 37 lines
drivers/mfd/tps6594.c new file +37 -0
+	regmap_write(tps->regmap, TPS6594_INT_STARTUP,
+		TPS6594_INT_STARTUP_NPWRON_START_INT |
+		TPS6594_INT_STARTUP_ENABLE_INT | TPS6594_INT_STARTUP_RTC_INT |
+		TPS6594_INT_STARTUP_SOFT_REBOOT_INT);
+
+	regmap_write(tps->regmap, TPS6594_INT_MISC,
+		TPS6594_INT_MISC_BIST_PASS_INT |
+		TPS6594_INT_MISC_EXT_CLK_INT | TPS6594_INT_MISC_TWARN_INT);
+
+	regmap_write(tps->regmap, TPS6594_CONFIG_1,
+		TPS6594_CONFIG_NSLEEP1_MASK | TPS6594_CONFIG_NSLEEP2_MASK);
+
+	regmap_write(tps->regmap, TPS6594_FSM_I2C_TRIGGERS,
+		TPS6594_FSM_I2C_TRIGGERS_I2C0);
+}
+
+static int tps6594_probe(struct i2c_client *client)
+{
+	struct tps6594 *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, &tps6594_regmap_config);
+	if (IS_ERR(ddata->regmap))
+		return dev_err_probe(ddata->dev, PTR_ERR(ddata->regmap),
+			"Failed to initialize register map\n");
+
+	ret = regmap_read(ddata->regmap, TPS6594_REG_DEV_REV, &otpid);
+	if (ret)
+		return dev_err_probe(ddata->dev, ret, "Failed to read OTP ID\n");

drivers/mfd/tps6594.c line 81

Quoted 10 lines
drivers/mfd/tps6594.c new file +10 -0
+
+	ddata->rev = otpid;
+	i2c_set_clientdata(client, ddata);
+
+	ret = mfd_add_devices(ddata->dev, PLATFORM_DEVID_AUTO, tps6594_cells,
+			      ARRAY_SIZE(tps6594_cells), NULL, 0, NULL);
+	if (ret)
+		return dev_err_probe(ddata->dev, ret, "Failed to register cells\n");
+
+	tps = ddata;

This should be in the if() statement below, no?

Quoted 7 lines
drivers/mfd/tps6594.c new file +7 -0
+	if (of_property_read_bool(node, "ti,system-power-controller"))
+		pm_power_off = tps6594_power_off;
+
+	return 0;
+}
+
+static const struct of_device_id of_tps6594_match_table[] = {

drivers/mfd/tps6594.c line 99

Quoted 10 lines
drivers/mfd/tps6594.c new file +10 -0
+	{ .compatible = "ti,tps6594", },
+	{}
+};
+MODULE_DEVICE_TABLE(of, of_tps6594_match_table);
+
+static const struct i2c_device_id tps6594_id_table[] = {
+	{ "tps6594", 0 },
+	{}
+};
+MODULE_DEVICE_TABLE(i2c, tps6594_id_table);

If you're using .probe_new() you can omit this table.

Quoted 87 lines
drivers/mfd/tps6594.c new file +13 -0
+static struct i2c_driver tps6594_driver = {
+	.driver	= {
+		.name	= "tps6594",
+		.of_match_table = of_tps6594_match_table,
+	},
+	.probe_new	= tps6594_probe,
+	.id_table	= tps6594_id_table,
+};
+module_i2c_driver(tps6594_driver);
+
+MODULE_AUTHOR("J Keerthy <[email protected]>");
+MODULE_DESCRIPTION("TPS6594 PMIC device driver");
+MODULE_LICENSE("GPL");
include/linux/mfd/tps6594.h new file +68 -0
new file mode 100644
index 000000000000..f721ec9880dd
@@ -0,0 +1,84 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Core driver interface for TI TPS6594 PMIC family
+ *
+ * Copyright (C) 2022 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#ifndef __MFD_TPS6594_H
+#define __MFD_TPS6594_H
+
+#include <linux/bits.h>
+
+/* TPS6594 chip ID list */
+#define TPS6594			0x00
+
+/* All register addresses */
+#define TPS6594_REG_DEV_REV			0x01
+#define TPS6594_INT_STARTUP			0x65
+#define TPS6594_INT_MISC			0x66
+#define TPS6594_CONFIG_1			0x7d
+#define TPS6594_FSM_I2C_TRIGGERS		0x85
+#define TPS6594_FSM_NSLEEP_TRIGGERS		0x86
+
+#define TPS6594_RTC_SECONDS			0xb5
+#define TPS6594_RTC_MINUTES			0xb6
+#define TPS6594_RTC_HOURS			0xb7
+#define TPS6594_RTC_DAYS			0xb8
+#define TPS6594_RTC_MONTHS			0xb9
+#define TPS6594_RTC_YEARS			0xba
+#define TPS6594_RTC_WEEKS			0xbb
+#define TPS6594_ALARM_SECONDS			0xbc
+#define TPS6594_ALARM_MINUTES			0xbd
+#define TPS6594_ALARM_HOURS			0xbe
+#define TPS6594_ALARM_DAYS			0xbf
+#define TPS6594_ALARM_MONTHS			0xc0
+#define TPS6594_ALARM_YEARS			0xc1
+#define TPS6594_RTC_CTRL_1			0xc2
+#define TPS6594_RTC_CTRL_2			0xc3
+#define TPS6594_RTC_STATUS			0xc4
+#define TPS6594_RTC_INTERRUPTS			0xc5
+#define TPS6594_REG_MAX			0xd0
+
+/* Register field definitions */
+#define TPS6594_DEV_REV_DEV_ID			0xff
+
+#define TPS6594_INT_STARTUP_NPWRON_START_INT	BIT(0)
+#define TPS6594_INT_STARTUP_ENABLE_INT		BIT(1)
+#define TPS6594_INT_STARTUP_RTC_INT		BIT(2)
+#define TPS6594_INT_STARTUP_FSD_INT		BIT(4)
+#define TPS6594_INT_STARTUP_SOFT_REBOOT_INT	BIT(5)
+
+#define TPS6594_INT_MISC_BIST_PASS_INT		BIT(0)
+#define TPS6594_INT_MISC_EXT_CLK_INT		BIT(1)
+#define TPS6594_INT_MISC_TWARN_INT		BIT(3)
+
+#define TPS6594_CONFIG_NSLEEP1_MASK		BIT(6)
+#define TPS6594_CONFIG_NSLEEP2_MASK		BIT(7)
+
+#define TPS6594_FSM_I2C_TRIGGERS_I2C0		BIT(0)
+
+#define TPS6594_FSM_NSLEEP_NSLEEP1B		BIT(0)
+#define TPS6594_FSM_NSLEEP_NSLEEP2B		BIT(1)
+
+#define TPS6594_RTC_CTRL_REG_GET_TIME		BIT(6)
+#define TPS6594_RTC_CTRL_REG_STOP_RTC		BIT(0)
+#define TPS6594_RTC_INTERRUPTS_REG_IT_ALARM	BIT(3)
+
+#define TPS6594_RTC_STATUS_RUN			BIT(1)

include/linux/mfd/tps6594.h line 78

Quoted 10 lines
include/linux/mfd/tps6594.h new file +10 -0
+
+/**
+ * struct tps6594 - state holder for the tps6594 driver
+ * @dev: struct device pointer for MFD device
+ * @rev: revision of the tps6594
+ * @lock: lock guarding the data structure
+ * @regmap: register map of the tps6594 PMIC
+ *
+ * Device data may be used to access the TPS6594 chip
+ */

This will not pass a W=1 build - please fix.

Quoted 9 lines
include/linux/mfd/tps6594.h new file +6 -0
+struct tps6594 {
+	struct device *dev;
+	u8 rev;
+	struct regmap *regmap;
+};
+#endif /* __MFD_TPS6594_H */
Signature · 1 line
2.38.GIT
Signature · 1 line
Lee Jones [李琼斯]
#8 lore raw

PATCH v5 3/4 rtc: rtc-tps6594: Add support for TPS6594 PMIC RTC

In reply to Matt Ranostay

From: Keerthy <[email protected]>

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

---
 drivers/rtc/Kconfig       |  10 +++
 drivers/rtc/Makefile      |   1 +
 drivers/rtc/rtc-tps6594.c | 155 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 166 insertions(+)
 create mode 100644 drivers/rtc/rtc-tps6594.c
drivers/rtc/Kconfig +10 -0
index ab9a1f814119..519dc544b083 100644
@@ -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_TPS6594
+	tristate "TI TPS6594 RTC driver"
+	depends on MFD_TPS6594 || COMPILE_TEST
+	help
+	  If you say yes here you get support for the RTC of TI TPS6594 series PMIC
+	  chips.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called rtc-tps6594.
+
 config RTC_DRV_RC5T583
 	tristate "RICOH 5T583 RTC driver"
 	depends on MFD_RC5T583
drivers/rtc/Makefile +1 -0
index d3c042dcbc73..4493a13f989d 100644
@@ -175,6 +175,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_TPS6594)	+= rtc-tps6594.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
drivers/rtc/rtc-tps6594.c new file +155 -0

155 lines not on this page · raw message

Signature · 1 line
2.38.GIT
#10 lore raw

Re: [PATCH v5 3/4] rtc: rtc-tps6594: Add support for TPS6594 PMIC RTC

In reply to Matt Ranostay

Hello,

Quoted 9 lines · Matt Ranostay
drivers/rtc/rtc-tps6594.c new file +9 -0
+static int tps6594_rtc_set_time(struct device *dev, struct rtc_time *tm)
+{
+	unsigned char rtc_data[TPS6594_NUM_TIME_REGS];
+	struct tps6594 *tps6594 = dev_get_drvdata(dev->parent);
+	unsigned int val;
+	int ret;
+
+	rtc_data[0] = bin2bcd(tm->tm_sec);
+	rtc_data[1] = bin2bcd(tm->tm_min);

drivers/rtc/rtc-tps6594.c line 81

Quoted 10 lines
drivers/rtc/rtc-tps6594.c new file +10 -0
+	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(tps6594->regmap, TPS6594_RTC_CTRL_1,
+				 TPS6594_RTC_CTRL_REG_STOP_RTC, 0);
+	if (ret < 0) {
+		dev_err(dev, "RTC stop failed, err = %d\n", ret);

This function is way too verbose. There is no other action for the user than retrying to set the time. You should probably remove all the dev_err calls.

Quoted 77 lines
drivers/rtc/rtc-tps6594.c new file +74 -0
+		return ret;
+	}
+
+	/* Waiting till RTC isn't running */
+	ret = regmap_read_poll_timeout(tps6594->regmap, TPS6594_RTC_STATUS,
+				       val, !(val & TPS6594_RTC_STATUS_RUN),
+				       TPS6594_RTC_POLL, TPS6594_RTC_TIMEOUT);
+	if (ret) {
+		dev_err(dev, "RTC_STATUS is still RUNNING\n");
+		return ret;
+	}
+
+	ret = regmap_bulk_write(tps6594->regmap, TPS6594_RTC_SECONDS,
+		rtc_data, TPS6594_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(tps6594->regmap, TPS6594_RTC_CTRL_1,
+				 TPS6594_RTC_CTRL_REG_STOP_RTC,
+				 TPS6594_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 tps6594_rtc_ops = {
+	.read_time	= tps6594_rtc_read_time,
+	.set_time	= tps6594_rtc_set_time,
+};
+
+static int tps6594_rtc_probe(struct platform_device *pdev)
+{
+	struct tps6594_rtc *tps6594_rtc;
+
+	tps6594_rtc = devm_kzalloc(&pdev->dev, sizeof(*tps6594_rtc), GFP_KERNEL);
+	if (!tps6594_rtc)
+		return -ENOMEM;
+
+	tps6594_rtc->dev = &pdev->dev;
+	platform_set_drvdata(pdev, tps6594_rtc);
+
+	tps6594_rtc->rtc = devm_rtc_allocate_device(&pdev->dev);
+	if (IS_ERR(tps6594_rtc->rtc))
+		return PTR_ERR(tps6594_rtc->rtc);
+
+	tps6594_rtc->rtc->ops = &tps6594_rtc_ops;
+
+	return devm_rtc_register_device(tps6594_rtc->rtc);
+}
+
+static const struct of_device_id of_tps6594_rtc_match[] = {
+	{ .compatible = "ti,tps6594-rtc", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, of_tps6594_rtc_match);
+
+static struct platform_driver tps6594_rtc_driver = {
+	.probe		= tps6594_rtc_probe,
+	.driver		= {
+		.name	= "tps6594-rtc",
+		.of_match_table = of_tps6594_rtc_match,
+	},
+};
+
+module_platform_driver(tps6594_rtc_driver);
+
+MODULE_ALIAS("platform:tps6594-rtc");
+MODULE_DESCRIPTION("TI TPS6594 series RTC driver");
+MODULE_AUTHOR("Keerthy J <[email protected]>");
+MODULE_LICENSE("GPL");
Signature · 1 line
2.38.GIT
Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#11 lore raw

PATCH v5 4/4 gpio: gpio-tps6594: add GPIO support for TPS6594 PMIC

In reply to Matt Ranostay

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

---
 drivers/gpio/Kconfig        |  9 +++++
 drivers/gpio/Makefile       |  1 +
 drivers/gpio/gpio-tps6594.c | 78 +++++++++++++++++++++++++++++++++++++
 include/linux/mfd/tps6594.h |  4 ++
 4 files changed, 92 insertions(+)
 create mode 100644 drivers/gpio/gpio-tps6594.c
drivers/gpio/Kconfig +9 -0
index ec7cfd4f52b1..f34b3746075a 100644
@@ -1405,6 +1405,15 @@ config GPIO_TPS65912
 	help
 	  This driver supports TPS65912 GPIO chip.
 
+config GPIO_TPS6594
+	tristate "TI TPS6594 GPIO driver"
+	depends on MFD_TPS6594 || COMPILE_TEST
+	select REGMAP
+	select GPIO_REGMAP
+	help
+	  Select this option to enable GPIO driver for the TPS6954
+	  PMIC chip family. There are 11 GPIOs that can be configured.
+
 config GPIO_TPS68470
 	tristate "TPS68470 GPIO"
 	depends on INTEL_SKL_INT3472
drivers/gpio/Makefile +1 -0
index 010587025fc8..31bef1cc112f 100644
@@ -159,6 +159,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_TPS6594)		+= gpio-tps6594.o
 obj-$(CONFIG_GPIO_TPS68470)		+= gpio-tps68470.o
 obj-$(CONFIG_GPIO_TQMX86)		+= gpio-tqmx86.o
 obj-$(CONFIG_GPIO_TS4800)		+= gpio-ts4800.o
drivers/gpio/gpio-tps6594.c new file +78 -0

78 lines not on this page · raw message

include/linux/mfd/tps6594.h +4 -0
index f721ec9880dd..758b1bc44178 100644
@@ -21,6 +21,10 @@
 #define TPS6594_FSM_I2C_TRIGGERS		0x85
 #define TPS6594_FSM_NSLEEP_TRIGGERS		0x86
 
+#define TPS6594_GPIO_CONF			0x31
+#define TPS6594_GPIO_OUT			0x3d
+#define TPS6594_GPIO_IN			0x3f
+
 #define TPS6594_RTC_SECONDS			0xb5
 #define TPS6594_RTC_MINUTES			0xb6
 #define TPS6594_RTC_HOURS			0xb7
Signature · 1 line
2.38.GIT
Reviewed-by on v5 4/4
#12 lore raw

Re: [PATCH v5 4/4] gpio: gpio-tps6594: add GPIO support for TPS6594 PMIC

Quoted 2 lines · Matt Ranostay

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

Reviewed-by on v5 4/4
#13 lore raw

Re: [PATCH v5 4/4] gpio: gpio-tps6594: add GPIO support for TPS6594 PMIC

In reply to Matt Ranostay

Am 2022-11-23 06:35, schrieb Matt Ranostay:

Quoted 4 lines
drivers/gpio/gpio-tps6594.c new file +4 -0
+static int tps6594_regmap_xlate(struct gpio_regmap *gpio,
+				    unsigned int base, unsigned int offset,
+				    unsigned int *reg, unsigned int *mask)
+{

drivers/gpio/gpio-tps6594.c line 33

Quoted 10 lines
drivers/gpio/gpio-tps6594.c new file +10 -0
+	if (base == TPS6594_GPIO_CONF) {
+		*reg = base + offset;
+		*mask = GPIO_CFG_MASK;
+	} else {
+		unsigned int line = offset % GPIO_BANK_SIZE;
+		unsigned int stride = offset / GPIO_BANK_SIZE;
+
+		*reg = base + stride;
+		*mask = BIT(line);
+	}

This looks like a duplcate from gpio_regmap_simple_xlate(). Maybe we can export it and do

if (base == TPS6594_GPIO_CONF) {
	*reg = base + offset;
	*mask = GPIO_CFG_MASK;
} else {
	return gpio_regmap_simple_xlate(gpio, base, offset, reg, mask);
}

Apart from that

-michael

Reviewed-by on the v5 series
#15 lore raw
In reply to Matt Ranostay
Quoted 2 lines · Matt Ranostay

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

For the series:

- Keerthy

Quoted 55 lines

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

Changes from v3:
* Refactoring gpio driver to use regmap gpio helpers
* Changing rtc driver to use more of device resource management
* Minor code changes related to error messages that aren't useful being dropped
* Dropped wildcard in device-tree compatible, and i2c device id
* Dropped device tree changes from the series; since these should be in their own series later

Changes from v4:
* Corrected commit messages for device tree documentation
* Added TPS6954 datasheet PDF to devicetree documentation
* Renamed all references, including filenames + configuration options, from tps6594x to tps6594 dropping the unneeded wildcard

Keerthy (2):
mfd: tps6594: Add support for TPS6594 PMIC devices
rtc: rtc-tps6594: Add support for TPS6594 PMIC RTC

Matt Ranostay (2):
dt-bindings: mfd: ti,tps6594: add TPS6594 PMIC support
gpio: gpio-tps6594: add GPIO support for TPS6594 PMIC

  .../devicetree/bindings/mfd/ti,tps6594.yaml   |  69 ++++++++
  drivers/gpio/Kconfig                          |   9 +
  drivers/gpio/Makefile                         |   1 +
  drivers/gpio/gpio-tps6594.c                   |  78 +++++++++
  drivers/mfd/Kconfig                           |  14 ++
  drivers/mfd/Makefile                          |   1 +
  drivers/mfd/tps6594.c                         | 113 +++++++++++++
  drivers/rtc/Kconfig                           |  10 ++
  drivers/rtc/Makefile                          |   1 +
  drivers/rtc/rtc-tps6594.c                     | 155 ++++++++++++++++++
  include/linux/mfd/tps6594.h                   |  88 ++++++++++
  11 files changed, 539 insertions(+)

create mode 100644 Documentation/devicetree/bindings/mfd/ti,tps6594.yaml create mode 100644 drivers/gpio/gpio-tps6594.c
create mode 100644 drivers/mfd/tps6594.c
create mode 100644 drivers/rtc/rtc-tps6594.c
create mode 100644 include/linux/mfd/tps6594.h