mbox series

[00/10] Add TWL6030 power off and powerbutton support

Message ID 20220820071659.1215-1-bavishimithil@gmail.com
Headers show
Series Add TWL6030 power off and powerbutton support | expand

Message

Mighty Aug. 20, 2022, 7:16 a.m. UTC
Hello!

This patchset is based off on an earlier series of patches submitted
https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1110053.html
It adds support for power off to the TWL6030 chipset, adds power button
support to the TWL6030 chipset, moves power driver to the correct
location, clean up in code from the original patch.

Thanks, Mithil

Mithil Bavishi (6):
  power: reset: Move TWL4030 power driver from mfd
  dt-bindings: power: reset: Move twl4030-power from mfd to power/reset
  dt-bindings: input: twl-pwrbutton: Add support for twl6030-pwrbutton
  dt-bindings: power: reset: Add bindings for twl6030-power
  input: misc: Rename twl4030_pwrbutton to twl_pwrbutton
  dt-bindings: input: Rename twl4030-pwrbutton to twl-pwrbutton

Paul Kocialkowski (4):
  power: reset: Add TWL6030 power driver, with minimal support for power
    off
  ARM: OMAP2+: Only select TWL4030_POWER for OMAP3
  ARM: OMAP2+: Select TWL6030_POWER for OMAP4
  input: misc: Add TWL6030 power button support to twl-pwrbutton

 ...wl4030-pwrbutton.txt => twl-pwrbutton.txt} |  5 +-
 .../{mfd => power/reset}/twl4030-power.txt    |  0
 .../bindings/power/reset/twl6030-power.txt    | 31 +++++++
 arch/arm/boot/dts/twl6030.dtsi                |  5 +
 arch/arm/configs/omap2plus_defconfig          |  2 +-
 arch/arm/mach-omap2/Kconfig                   |  3 +-
 drivers/input/misc/Kconfig                    |  8 +-
 drivers/input/misc/Makefile                   |  2 +-
 .../{twl4030-pwrbutton.c => twl-pwrbutton.c}  | 75 ++++++++++-----
 drivers/mfd/Kconfig                           | 13 ---
 drivers/mfd/Makefile                          |  1 -
 drivers/power/reset/Kconfig                   | 22 +++++
 drivers/power/reset/Makefile                  |  2 +
 drivers/{mfd => power/reset}/twl4030-power.c  |  0
 drivers/power/reset/twl6030-power.c           | 93 +++++++++++++++++++
 include/linux/mfd/twl.h                       |  1 +
 16 files changed, 217 insertions(+), 46 deletions(-)
 rename Documentation/devicetree/bindings/input/{twl4030-pwrbutton.txt => twl-pwrbutton.txt} (72%)
 rename Documentation/devicetree/bindings/{mfd => power/reset}/twl4030-power.txt (100%)
 create mode 100644 Documentation/devicetree/bindings/power/reset/twl6030-power.txt
 rename drivers/input/misc/{twl4030-pwrbutton.c => twl-pwrbutton.c} (55%)
 rename drivers/{mfd => power/reset}/twl4030-power.c (100%)
 create mode 100644 drivers/power/reset/twl6030-power.c

Comments

Rob Herring Aug. 22, 2022, 7:24 p.m. UTC | #1
On Sat, Aug 20, 2022 at 12:46:55PM +0530, Mithil Bavishi wrote:
> Adds documentation for the twl6030 power driver.
> 
> Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
> Signed-off-by: Mithil Bavishi <bavishimithil@gmail.com>
> ---
>  .../bindings/power/reset/twl6030-power.txt    | 31 +++++++++++++++++++

New bindings must be DT schema format.

>  1 file changed, 31 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/power/reset/twl6030-power.txt
> 
> diff --git a/Documentation/devicetree/bindings/power/reset/twl6030-power.txt b/Documentation/devicetree/bindings/power/reset/twl6030-power.txt
> new file mode 100644
> index 000000000..946bb3d9f
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/power/reset/twl6030-power.txt
> @@ -0,0 +1,31 @@
> +Texas Instruments TWL family (twl6030) reset and power management module
> +
> +For now, the binding only supports the complete shutdown of the system after
> +poweroff.
> +
> +Required properties:
> +- compatible : must be
> +       "ti,twl6030-power"
> +
> +Optional properties:
> +
> +- ti,system-power-controller: This indicates that TWL6030 is the

We have a generic property for this.

> +  power supply master of the system. With this flag, the chip will
> +  initiate an ACTIVE-to-OFF or SLEEP-to-OFF transition when the
> +  system poweroffs.
> +
> +Example:
> +&i2c1 {
> +       clock-frequency = <2600000>;
> +
> +       twl: twl@48 {
> +               reg = <0x48>;
> +               interrupts = <7>; /* SYS_NIRQ cascaded to intc */
> +               interrupt-parent = <&intc>;
> +
> +               twl_power: power {
> +                       compatible = "ti,twl6030-power";
> +                       ti,system-power-controller;

Why do you need a child node here? There aren't any resources for the 
sub-block.

Rob
Rob Herring Aug. 22, 2022, 7:25 p.m. UTC | #2
On Sat, 20 Aug 2022 12:46:54 +0530, Mithil Bavishi wrote:
> Adds documentation for the compatible string for twl6030 powerbutton
> support.
> 
> Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
> Signed-off-by: Mithil Bavishi <bavishimithil@gmail.com>
> ---
>  Documentation/devicetree/bindings/input/twl4030-pwrbutton.txt | 1 +
>  1 file changed, 1 insertion(+)
> 

Acked-by: Rob Herring <robh@kernel.org>
Rob Herring Aug. 22, 2022, 7:26 p.m. UTC | #3
On Sat, Aug 20, 2022 at 12:46:59PM +0530, Mithil Bavishi wrote:
> This changes the Documentation of the twl4030-pwrbutton to
> make it more generic as it can support other chips than
> twl4030 as well.

This should be part of patch 4.

> 
> Signed-off-by: Mithil Bavishi <bavishimithil@gmail.com>
> ---
>  .../input/{twl4030-pwrbutton.txt => twl-pwrbutton.txt}        | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>  rename Documentation/devicetree/bindings/input/{twl4030-pwrbutton.txt => twl-pwrbutton.txt} (81%)
> 
> diff --git a/Documentation/devicetree/bindings/input/twl4030-pwrbutton.txt b/Documentation/devicetree/bindings/input/twl-pwrbutton.txt
> similarity index 81%
> rename from Documentation/devicetree/bindings/input/twl4030-pwrbutton.txt
> rename to Documentation/devicetree/bindings/input/twl-pwrbutton.txt
> index 9a0b765d3..43addc04d 100644
> --- a/Documentation/devicetree/bindings/input/twl4030-pwrbutton.txt
> +++ b/Documentation/devicetree/bindings/input/twl-pwrbutton.txt
> @@ -1,6 +1,6 @@
> -Texas Instruments TWL family (twl4030) pwrbutton module
> +Texas Instruments TWL family pwrbutton module
>  
> -This module is part of the TWL4030. For more details about the whole
> +This module is part of a TWL chip. For more details about the whole
>  chip see Documentation/devicetree/bindings/mfd/twl-family.txt.
>  
>  This module provides a simple power button event via an Interrupt.
> -- 
> 2.25.1
> 
>
Lee Jones Sept. 6, 2022, 3:13 p.m. UTC | #4
On Sat, 20 Aug 2022, Mithil Bavishi wrote:

> The power/reset folder seems like a more appropriate place for
> twl4030-power.c
> 
> Signed-off-by: Mithil Bavishi <bavishimithil@gmail.com>
> ---
>  drivers/mfd/Kconfig                          | 13 -------------
>  drivers/mfd/Makefile                         |  1 -
>  drivers/power/reset/Kconfig                  | 12 ++++++++++++
>  drivers/power/reset/Makefile                 |  1 +
>  drivers/{mfd => power/reset}/twl4030-power.c |  0
>  5 files changed, 13 insertions(+), 14 deletions(-)
>  rename drivers/{mfd => power/reset}/twl4030-power.c (100%)

Acked-by: Lee Jones <lee@kernel.org>
Sebastian Reichel Sept. 11, 2022, 12:55 p.m. UTC | #5
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
>