From: Matt Ranostay <mranostay@ti.com>
To: <vigneshr@ti.com>, <robh@kernel.org>,
<krzysztof.kozlowski@linaro.org>, <a.zummo@towertech.it>,
<linus.walleij@linaro.org>, <lee@kernel.org>, <brgl@bgdev.pl>
Cc: <linux-arm-kernel@lists.infradead.org>,
<devicetree@vger.kernel.org>, <linux-gpio@vger.kernel.org>,
<linux-rtc@vger.kernel.org>, Keerthy <j-keerthy@ti.com>,
Matt Ranostay <mranostay@ti.com>
Subject: [PATCH v4 3/4] rtc: rtc-tps6594x: Add support for TPS6594X PMIC RTC
Date: Fri, 18 Nov 2022 01:22:17 -0800 [thread overview]
Message-ID: <20221118092218.480147-4-mranostay@ti.com> (raw)
In-Reply-To: <20221118092218.480147-1-mranostay@ti.com>
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 | 155 +++++++++++++++++++++++++++++++++++++
3 files changed, 166 insertions(+)
create mode 100644 drivers/rtc/rtc-tps6594x.c
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index ab9a1f814119..50e0de4d6eb3 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 || COMPILE_TEST
+ 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 d3c042dcbc73..5e3a3b06fc20 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -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_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..20fe076112e6
--- /dev/null
+++ b/drivers/rtc/rtc-tps6594x.c
@@ -0,0 +1,155 @@
+// 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
+ */
+
+#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_RTC_POLL 20000
+#define TPS6594X_RTC_TIMEOUT 100000
+
+#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)
+ 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)
+ return ret;
+
+ ret = regmap_bulk_read(tps6594x->regmap, TPS6594X_RTC_SECONDS,
+ rtc_data, TPS6594X_NUM_TIME_REGS);
+ if (ret < 0)
+ 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);
+ unsigned int val;
+ int ret;
+
+ 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 */
+ ret = regmap_read_poll_timeout(tps6594x->regmap, TPS6594X_RTC_STATUS,
+ val, !(val & TPS6594X_RTC_STATUS_RUN),
+ TPS6594X_RTC_POLL, TPS6594X_RTC_TIMEOUT);
+ if (ret) {
+ dev_err(dev, "RTC_STATUS is still RUNNING\n");
+ return ret;
+ }
+
+ 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_rtc *tps6594x_rtc;
+
+ tps6594x_rtc = devm_kzalloc(&pdev->dev, sizeof(*tps6594x_rtc), GFP_KERNEL);
+ if (!tps6594x_rtc)
+ return -ENOMEM;
+
+ tps6594x_rtc->dev = &pdev->dev;
+ platform_set_drvdata(pdev, tps6594x_rtc);
+
+ tps6594x_rtc->rtc = devm_rtc_allocate_device(&pdev->dev);
+ if (IS_ERR(tps6594x_rtc->rtc))
+ return PTR_ERR(tps6594x_rtc->rtc);
+
+ tps6594x_rtc->rtc->ops = &tps6594x_rtc_ops;
+
+ return devm_rtc_register_device(tps6594x_rtc->rtc);
+}
+
+static const struct of_device_id of_tps6594x_rtc_match[] = {
+ { .compatible = "ti,tps6594-rtc", },
+ {},
+};
+MODULE_DEVICE_TABLE(of, of_tps6594x_rtc_match);
+
+static struct platform_driver tps6594x_rtc_driver = {
+ .probe = tps6594x_rtc_probe,
+ .driver = {
+ .name = "tps6594-rtc",
+ .of_match_table = of_tps6594x_rtc_match,
+ },
+};
+
+module_platform_driver(tps6594x_rtc_driver);
+
+MODULE_ALIAS("platform:tps6594-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
next prev parent reply other threads:[~2022-11-18 9:24 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-18 9:22 [PATCH v4 0/4] mfd: add tps6594x support for Jacinto platforms Matt Ranostay
2022-11-18 9:22 ` [PATCH v4 1/4] Documentation: ti,tps6594: Add DT bindings for the TPS6594x PMIC Matt Ranostay
2022-11-18 10:21 ` Krzysztof Kozlowski
2022-11-19 4:23 ` Matt Ranostay
2022-11-18 13:31 ` Rob Herring
2022-11-18 9:22 ` [PATCH v4 2/4] MFD: TPS6594x: Add new PMIC device driver for TPS6594x chips Matt Ranostay
2022-11-18 10:23 ` Krzysztof Kozlowski
2022-11-19 4:17 ` Matt Ranostay
2022-11-18 9:22 ` Matt Ranostay [this message]
2022-11-18 9:22 ` [PATCH v4 4/4] gpio: gpio-tps6594x: add GPIO support for TPS6594x PMIC Matt Ranostay
2022-11-28 18:08 ` Bartosz Golaszewski
2022-11-28 20:38 ` Linus Walleij
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221118092218.480147-4-mranostay@ti.com \
--to=mranostay@ti.com \
--cc=a.zummo@towertech.it \
--cc=brgl@bgdev.pl \
--cc=devicetree@vger.kernel.org \
--cc=j-keerthy@ti.com \
--cc=krzysztof.kozlowski@linaro.org \
--cc=lee@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-rtc@vger.kernel.org \
--cc=robh@kernel.org \
--cc=vigneshr@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox