From: Neil Armstrong <neil.armstrong@linaro.org>
To: Martin Blumenstingl <martin.blumenstingl@googlemail.com>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Rob Herring <robh+dt@kernel.org>,
Kevin Hilman <khilman@baylibre.com>,
Sebastian Reichel <sre@kernel.org>,
Jerome Brunet <jbrunet@baylibre.com>
Cc: linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-amlogic@lists.infradead.org,
devicetree@vger.kernel.org,
Neil Armstrong <neil.armstrong@linaro.org>
Subject: [PATCH 2/4] power: reset: add Odroid Go Ultra poweroff driver
Date: Mon, 31 Oct 2022 17:47:26 +0100 [thread overview]
Message-ID: <20221031-b4-odroid-go-ultra-initial-v1-2-42e3dbea86d5@linaro.org> (raw)
In-Reply-To: <20221031-b4-odroid-go-ultra-initial-v1-0-42e3dbea86d5@linaro.org>
The Hardkernel Odroid Go Ultra poweroff scheme requires requesting a poweroff
to its two PMICs in order, this represents the poweroff scheme needed to complete
a clean poweroff of the system.
This implement this scheme, and overrides the PSCI pm_power_off.
Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
---
drivers/power/reset/Kconfig | 7 ++
drivers/power/reset/Makefile | 1 +
drivers/power/reset/odroid-go-ultra-poweroff.c | 122 +++++++++++++++++++++++++
3 files changed, 130 insertions(+)
diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
index a8c46ba5878f..26860c2e05a9 100644
--- a/drivers/power/reset/Kconfig
+++ b/drivers/power/reset/Kconfig
@@ -141,6 +141,13 @@ config POWER_RESET_OCELOT_RESET
help
This driver supports restart for Microsemi Ocelot SoC and similar.
+config POWER_RESET_ODROID_GO_ULTRA_POWEROFF
+ bool "Odroid Go Ultra power-off driver"
+ depends on ARCH_MESON || COMPILE_TEST
+ depends on MFD_RK808
+ help
+ This driver supports Power off for Odroid Go Ultra device.
+
config POWER_RESET_OXNAS
bool "OXNAS SoC restart driver"
depends on ARCH_OXNAS
diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile
index 0a39424fc558..d763e6735ee3 100644
--- a/drivers/power/reset/Makefile
+++ b/drivers/power/reset/Makefile
@@ -17,6 +17,7 @@ obj-$(CONFIG_POWER_RESET_MT6323) += mt6323-poweroff.o
obj-$(CONFIG_POWER_RESET_OXNAS) += oxnas-restart.o
obj-$(CONFIG_POWER_RESET_QCOM_PON) += qcom-pon.o
obj-$(CONFIG_POWER_RESET_OCELOT_RESET) += ocelot-reset.o
+obj-$(CONFIG_POWER_RESET_ODROID_GO_ULTRA_POWEROFF) += odroid-go-ultra-poweroff.o
obj-$(CONFIG_POWER_RESET_PIIX4_POWEROFF) += piix4-poweroff.o
obj-$(CONFIG_POWER_RESET_LTC2952) += ltc2952-poweroff.o
obj-$(CONFIG_POWER_RESET_QNAP) += qnap-poweroff.o
diff --git a/drivers/power/reset/odroid-go-ultra-poweroff.c b/drivers/power/reset/odroid-go-ultra-poweroff.c
new file mode 100644
index 000000000000..89ae21790f65
--- /dev/null
+++ b/drivers/power/reset/odroid-go-ultra-poweroff.c
@@ -0,0 +1,122 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2022 Neil Armstrong <neil.armstrong@linaro.org>
+ */
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/of_platform.h>
+#include <linux/mfd/rk808.h>
+#include <linux/regmap.h>
+#include <linux/module.h>
+#include <linux/i2c.h>
+
+static struct rk808 *rk817;
+static struct rk808 *rk818;
+
+static void odroid_go_ultra_do_poweroff(void)
+{
+ int ret;
+
+ BUG_ON(!rk817);
+ BUG_ON(!rk818);
+
+ /* RK817 */
+ ret = regmap_update_bits(rk817->regmap, RK817_SYS_CFG(3), DEV_OFF, DEV_OFF);
+ if (ret)
+ pr_err("%s: failed to poweroff rk817\n", __func__);
+
+ /* RK818 */
+ ret = regmap_update_bits(rk818->regmap, RK818_DEVCTRL_REG, DEV_OFF, DEV_OFF);
+ if (ret)
+ pr_err("%s: failed to poweroff rk817\n", __func__);
+
+ WARN_ON(1);
+}
+
+static int odroid_go_ultra_poweroff_get_pmic_drvdata(struct platform_device *pdev,
+ const char *property,
+ struct rk808 **pmic)
+{
+ struct device_node *pmic_node;
+ struct i2c_client *pmic_client;
+
+ pmic_node = of_parse_phandle(pdev->dev.of_node, property, 0);
+ if (!pmic_node)
+ return -ENODEV;
+
+ pmic_client = of_find_i2c_device_by_node(pmic_node);
+ of_node_put(pmic_node);
+ if (!pmic_client)
+ return -EPROBE_DEFER;
+
+ *pmic = i2c_get_clientdata(pmic_client);
+
+ put_device(&pmic_client->dev);
+
+ if (!*pmic)
+ return -EPROBE_DEFER;
+
+ return 0;
+}
+
+static int odroid_go_ultra_poweroff_probe(struct platform_device *pdev)
+{
+ int ret;
+
+ /* RK818 */
+ ret = odroid_go_ultra_poweroff_get_pmic_drvdata(pdev, "hardkernel,rk818-pmic", &rk818);
+ if (ret) {
+ dev_err(&pdev->dev, "failed to get rk818 mfd data (%d)\n", ret);
+ return ret;
+ }
+
+ /* RK817 */
+ ret = odroid_go_ultra_poweroff_get_pmic_drvdata(pdev, "hardkernel,rk817-pmic", &rk817);
+ if (ret) {
+ dev_err(&pdev->dev, "failed to get rk817 mfd data (%d)\n", ret);
+ return ret;
+ }
+
+ /* If a pm_power_off function has already been added, warn we're overriding */
+ if (pm_power_off != NULL)
+ dev_warn(&pdev->dev,
+ "%s: pm_power_off function already registered, overriding\n",
+ __func__);
+
+ pm_power_off = odroid_go_ultra_do_poweroff;
+
+ return 0;
+}
+
+static int odroid_go_ultra_poweroff_remove(struct platform_device *pdev)
+{
+ if (pm_power_off == &odroid_go_ultra_do_poweroff)
+ pm_power_off = NULL;
+
+ rk817 = NULL;
+ rk818 = NULL;
+
+ return 0;
+}
+
+static const struct of_device_id of_odroid_go_ultra_poweroff_match[] = {
+ { .compatible = "hardkernel,odroid-go-ultra-poweroff", },
+ {},
+};
+MODULE_DEVICE_TABLE(of, of_odroid_go_ultra_poweroff_match);
+
+static struct platform_driver odroid_go_ultra_poweroff_driver = {
+ .probe = odroid_go_ultra_poweroff_probe,
+ .remove = odroid_go_ultra_poweroff_remove,
+ .driver = {
+ .name = "odroid-go-ultra-poweroff",
+ .of_match_table = of_odroid_go_ultra_poweroff_match,
+ },
+};
+
+module_platform_driver(odroid_go_ultra_poweroff_driver);
+
+MODULE_AUTHOR("Neil Armstrong <neil.armstrong@linaro.org>");
+MODULE_DESCRIPTION("Odroid Go Ultra poweroff driver");
+MODULE_LICENSE("GPL");
--
b4 0.10.1
next prev parent reply other threads:[~2022-10-31 16:47 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-31 16:47 [PATCH 0/4] arm64: amlogic: add initial Odroid Go Ultra DTS Neil Armstrong
2022-10-31 16:47 ` [PATCH 1/4] dt-bindings: reset: document Odroid Go Ultra power-off Neil Armstrong
2022-10-31 21:16 ` Martin Blumenstingl
2022-11-02 8:47 ` Neil Armstrong
2022-11-02 16:23 ` Rob Herring
2022-11-02 16:26 ` Neil Armstrong
2022-10-31 16:47 ` Neil Armstrong [this message]
2022-10-31 22:29 ` [PATCH 2/4] power: reset: add Odroid Go Ultra poweroff driver Sebastian Reichel
2022-11-02 8:48 ` Neil Armstrong
2022-10-31 16:47 ` [PATCH 3/4] dt-bindings: amlogic: document Odroid Go Ultra compatible Neil Armstrong
2022-10-31 21:18 ` Martin Blumenstingl
2022-11-02 16:24 ` Rob Herring
2022-10-31 16:47 ` [PATCH 4/4] arm64: dts: amlogic: add initial Odroid Go Ultra DTS Neil Armstrong
2022-11-02 19:16 ` Krzysztof Kozlowski
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=20221031-b4-odroid-go-ultra-initial-v1-2-42e3dbea86d5@linaro.org \
--to=neil.armstrong@linaro.org \
--cc=devicetree@vger.kernel.org \
--cc=jbrunet@baylibre.com \
--cc=khilman@baylibre.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-amlogic@lists.infradead.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=martin.blumenstingl@googlemail.com \
--cc=robh+dt@kernel.org \
--cc=sre@kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).