[PATCH 2/9] power: reset: add Photonicat PMU poweroff driver
Krzysztof Kozlowski
krzk at kernel.org
Fri Sep 6 02:44:54 PDT 2024
On 06/09/2024 11:36, Junhao Xie wrote:
> This driver implements the shutdown function of Photonicat PMU:
>
> - Host notifies PMU to shutdown:
> When powering off, a shutdown command (0x0F) needs to be sent
> to the MCU.
>
> - PMU notifies host to shutdown:
> If the power button is long pressed, the MCU will send a shutdown
> command (0x0D) to the system.
> If system does not shutdown within 60 seconds,
> the power will be turned off directly.
>
> Signed-off-by: Junhao Xie <bigfoot at classfun.cn>
> ---
> drivers/power/reset/Kconfig | 12 +++
> drivers/power/reset/Makefile | 1 +
> drivers/power/reset/photonicat-poweroff.c | 95 +++++++++++++++++++++++
> 3 files changed, 108 insertions(+)
> create mode 100644 drivers/power/reset/photonicat-poweroff.c
>
> diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
> index fece990af4a7..c59529ce25a2 100644
> --- a/drivers/power/reset/Kconfig
> +++ b/drivers/power/reset/Kconfig
> @@ -148,6 +148,18 @@ config POWER_RESET_ODROID_GO_ULTRA_POWEROFF
> help
> This driver supports Power off for Odroid Go Ultra device.
>
> +config POWER_RESET_PHOTONICAT_POWEROFF
> + tristate "Photonicat PMU power-off driver"
> + depends on MFD_PHOTONICAT_PMU
|| COMPILE_TEST, no?
> + help
> + This driver supports Power off for Photonicat PMU device.
> +
> + Supports operations:
> + Host notifies PMU to shutdown
> + PMU notifies host to shutdown
> +
> + Say Y if you have a Photonicat board.
> +
> config POWER_RESET_PIIX4_POWEROFF
> tristate "Intel PIIX4 power-off driver"
> depends on PCI
> diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile
> index a95d1bd275d1..339b36812b95 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_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_PHOTONICAT_POWEROFF) += photonicat-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/photonicat-poweroff.c b/drivers/power/reset/photonicat-poweroff.c
> new file mode 100644
> index 000000000000..f9f1ea179247
> --- /dev/null
> +++ b/drivers/power/reset/photonicat-poweroff.c
> @@ -0,0 +1,95 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright (c) 2024 Junhao Xie <bigfoot at classfun.cn>
> + */
> +
> +#include <linux/mfd/photonicat-pmu.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/platform_device.h>
> +#include <linux/reboot.h>
> +
> +struct pcat_poweroff {
> + struct device *dev;
> + struct pcat_pmu *pmu;
> + struct notifier_block nb;
> +};
> +
> +static int pcat_do_poweroff(struct sys_off_data *data)
> +{
> + struct pcat_poweroff *poweroff = data->cb_data;
> +
> + dev_info(poweroff->dev, "Host request PMU shutdown\n");
> + pcat_pmu_write_data(poweroff->pmu, PCAT_CMD_HOST_REQUEST_SHUTDOWN,
> + NULL, 0);
> +
> + return NOTIFY_DONE;
> +}
> +
> +static int pcat_poweroff_notify(struct notifier_block *nb, unsigned long action,
> + void *data)
> +{
> + struct pcat_poweroff *poweroff =
> + container_of(nb, struct pcat_poweroff, nb);
> +
> + if (action != PCAT_CMD_PMU_REQUEST_SHUTDOWN)
> + return NOTIFY_DONE;
> +
> + dev_info(poweroff->dev, "PMU request host shutdown\n");
Nope. Drop.
> + orderly_poweroff(true);
> +
> + return NOTIFY_DONE;
Best regards,
Krzysztof
More information about the Linux-rockchip
mailing list