Re: [PATCH 03/10] power: reset: Add TWL6030 power driver, with minimal support for power off

Sebastian Reichel
2022-09-12T10:28:44Z

[-- Attachment #1: Type: text/plain, Size: 5193 bytes --]

Hi,

On Sat, Aug 20, 2022 at 12:46:53PM +0530, Mithil Bavishi wrote:
> From: Paul Kocialkowski <contact@paulk.fr>
>
> This adds a TWL6030 power driver, that currently only supports powering
> off the device when the TWL is used as system power controller.
>
> This driver might be extended to support more power-related features of the
> TWL6030.
>
> Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
> Signed-off-by: Mithil Bavishi <bavishimithil@gmail.com>
> ---
> drivers/power/reset/Kconfig | 10 ++++
> drivers/power/reset/Makefile | 1 +
> drivers/power/reset/twl6030-power.c | 93 +++++++++++++++++++++++++++++
> 3 files changed, 104 insertions(+)
> create mode 100644 drivers/power/reset/twl6030-power.c
>
> diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
> index 39117b697..5156b1613 100644
> --- a/drivers/power/reset/Kconfig
> +++ b/drivers/power/reset/Kconfig
> @@ -316,3 +316,13 @@ config TWL4030_POWER
> and load scripts controlling which resources are switched off/on
> or reset when a sleep, wakeup or warm reset event occurs.
> endif
> +
> +config TWL6030_POWER
> + bool "TI TWL6030 power resources"
> + depends on TWL4030_CORE && ARM
> + help
> + Say yes here if you want to use the power resources on the
> + TWL6030 family chips.
> +
> + When used as system power controller, this driver allows turning off
> + the main power supply.
> diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile
> index e9db25b09..692d51cef 100644
> --- a/drivers/power/reset/Makefile
> +++ b/drivers/power/reset/Makefile
> @@ -37,3 +37,4 @@ obj-$(CONFIG_POWER_RESET_SC27XX) += sc27xx-poweroff.o
> obj-$(CONFIG_NVMEM_REBOOT_MODE) += nvmem-reboot-mode.o
> obj-$(CONFIG_POWER_MLXBF) += pwr-mlxbf.o
> obj-$(CONFIG_TWL4030_POWER) += twl4030-power.o
> +obj-$(CONFIG_TWL6030_POWER) += twl6030-power.o
> diff --git a/drivers/power/reset/twl6030-power.c b/drivers/power/reset/twl6030-power.c
> new file mode 100644
> index 000000000..78c8a02a3
> --- /dev/null
> +++ b/drivers/power/reset/twl6030-power.c
> @@ -0,0 +1,93 @@
> +/*
> + * TWL6030 power
> + *
> + * Copyright (C) 2016 Paul Kocialkowski <contact@paulk.fr>
> + *
> + * This file is subject to the terms and conditions of the GNU General
> + * Public License. See the file "COPYING" in the main directory of this
> + * archive for more details.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + */

Please use SPDX format for license.

> +
> +#include <linux/module.h>
> +#include <linux/pm.h>
> +#include <linux/mfd/twl.h>
> +#include <linux/platform_device.h>
> +#include <linux/of.h>
> +#include <linux/of_device.h>
> +
> +#define TWL6030_PHOENIX_DEV_ON 0x25
> +
> +#define TWL6030_PHOENIX_APP_DEVOFF BIT(0)
> +#define TWL6030_PHOENIX_CON_DEVOFF BIT(1)
> +#define TWL6030_PHOENIX_MOD_DEVOFF BIT(2)
> +
> +void twl6030_power_off(void)
> +{
> + int err;
> +
> + err = twl_i2c_write_u8(TWL6030_MODULE_ID0, TWL6030_PHOENIX_APP_DEVOFF |
> + TWL6030_PHOENIX_CON_DEVOFF | TWL6030_PHOENIX_MOD_DEVOFF,
> + TWL6030_PHOENIX_DEV_ON);
> + if (err)
> + pr_err("TWL6030 Unable to power off\n");
> +}
> +
> +static bool twl6030_power_use_poweroff(struct device_node *node)
> +{
> + if (of_property_read_bool(node, "ti,system-power-controller"))
> + return true;
> +
> + return false;
> +}
> +
> +#ifdef CONFIG_OF
> +static const struct of_device_id twl6030_power_of_match[] = {
> + {
> + .compatible = "ti,twl6030-power",
> + },
> + { },
> +};
> +
> +MODULE_DEVICE_TABLE(of, twl6030_power_of_match);
> +#endif /* CONFIG_OF */
> +
> +static int twl6030_power_probe(struct platform_device *pdev)
> +{
> + struct device_node *node = pdev->dev.of_node;
> +
> + if (!node) {
> + dev_err(&pdev->dev, "Platform data is missing\n");
> + return -EINVAL;
> + }
> +
> + /* Board has to be wired properly to use this feature */
> + if (twl6030_power_use_poweroff(node) && !pm_power_off)
> + pm_power_off = twl6030_power_off;

Please devm_register_sys_off_handler or devm_register_power_off_handler().

> +
> + return 0;
> +}
> +
> +static int twl6030_power_remove(struct platform_device *pdev)
> +{
> + return 0;
> +}

Empty remove function can be removed.

> +
> +static struct platform_driver twl6030_power_driver = {
> + .driver = {
> + .name = "twl6030_power",
> + .of_match_table = of_match_ptr(twl6030_power_of_match),

The driver is not useful without CONFIG_OF, so you can just remove the
#ifdef around twl6030_power_of_match and drop of_match_ptr here.

-- Sebastian

> + },
> + .probe = twl6030_power_probe,
> + .remove = twl6030_power_remove,
> +};
> +
> +module_platform_driver(twl6030_power_driver);
> +
> +MODULE_AUTHOR("Paul Kocialkowski <contact@paulk.fr>");
> +MODULE_DESCRIPTION("Power management for TWL6030");
> +MODULE_LICENSE("GPL");
> --
> 2.25.1
>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]